Google

Monday, April 12, 2010

CSC202 Revision April 14

Note: above is solution to Question 2

QUESTION 1:

Develop a program that will determine the gross pay for each of several employees. The
company pays "straight-time" for the first 40 hours worked by each employee and pays "timeand-
a-half" for all hours worked in excess of 40 hours. You are given a list of employees of the
company, the number of hours each employee worked last week and the hourly rate of each
employee. Your program should input this information for each employee, and should
determine and display the employee's gross pay. Here is a sample input/output dialog:
Enter # of hours worked: 41
Enter hourly rate of the worker: 10.00
Salary is $415.00


SOLUTION:

#include "stdio.h"

void main(){
float hours_worked,hourly_rate,salary;

printf("Enter # of hours worked: ");
scanf("%f",&hours_worked);

printf("Enter hourly rate of the worker: ");
scanf("%f",&hourly_rate);

if(hours_worked<=40){
salary = hours_worked*hourly_rate;
}else{
salary = 40*hourly_rate + (hours_worked-40)*hourly_rate*1.5;
}

printf("Salary is $%.2f\n",salary);
}

QUESTION 2:
(a) Define an array to input 10 elements of type string (hint: use char array);
string “hello”.

(c) Write a loop to print out all the array elements in (b).

SOLUTION 2: