/****************************************************** ** Name: ** Filename: grosspay.cpp ** Project #: Deitel & Deitel 2.19 ** Project Description: Write a program that will determine the gross pay for each of several employees. ** Output: Salary in dollars ** Input: Hours worked Hourly rate of worker ** Algorithm: Enter hours worked: Enter hourly rate of worker: Hours <= 40 then salary = hours worked * hourly rate Hours > 40 then calculate hours over 40 Hourly half pay = ( hours over * hourly rate ) * 1/2 Salary for worker with over 40 hours = (hours * hourly rate) + half pay; Print Salary for each worker Enter -1 to end program ******************************************************/ // Include files #include // used for cin, cout #include using namespace std; #include // Global Type Declarations // Function Prototypes void instruct (void); void pause (); //Global Variables - should not be used without good reason. int main () { // Declaration section double salary, // salary of worker hours, // hours worked hrate, // hourly rate ots, // hourly half pay hoursover; // hours over 40 // Executable section instruct (); cout << "Enter hours worked (-1 to end): " << setiosflags ( ios::fixed | ios::showpoint ); cin >> hours; while ( hours != -1 ) { cout << "Enter hourly rate of the worker ($00.00): "; cin >> hrate; if ( hours <= 40 ) salary = hours * hrate; hoursover = hours - 40; ots = ( hoursover * hrate ) * .5; if ( hours > 40 ) salary = ( hours * hrate ) + ots; cout << "Salary is $" << setprecision ( 2 ) << salary << "\n\nEnter hours worked (-1 to end): "; cin >> hours; } pause (); return 0; } void instruct (void) { // Declaration section // Executable section cout << "The following program will determine the gross pay of\n" << "several employees including overtime calculations.\n" << "Input the hours worked and the hourly rate of each\n" << "employee.\n"<< endl; } void pause () { // Declaration section // Executable section cout << "\nPress any key to continue..."; getch(); cout << "\r"; cout << " "; cout << "\r"; } /* Program Output Enter hours worked (-1 to end): 40 Enter hourly rate of the worker ($00.00): 20.00 Salary is $800.00 Enter hours worked (-1 to end): 45 Enter hourly rate of the worker ($00.00): 20.00 Salary is $950.00 Enter hours worked (-1 to end): -1 Press any key to continue... */