Question: Here is the question: In this exercise, you will create a program that displays the gross pay for one or more Employees. Use a negative

Here is the question:

In this exercise, you will create a program that displays the gross pay for one or more Employees. Use a negative sentinel value to stop the program. Employees are paid at their regular pay rate for hours worked from 1 through 37. They are paid time and a half for the hours worked from 38 through 50, and double-time for the hours worked over 50. Use a void function to calculate and return the employees overtime pay, if applicable.

I am able to get the correct calculated output. The issue I am having is when entering -1 to stop the loop it continues. Please advise what I have done wrong. Thanks!

#include

#include

using namespace std;

double getGrossPay(int hours, double payRate);

int main()

{

int dummy;

int hours = 0;

double payRate = 0.0;

double grossPay = 0.0;

while (hours != -1)

{

cout << "Enter the number of hours the employee worked (: enter -1 to stop) ";

cin >> hours;

cout << "Enter employee's hourly pay rate: ";

cin >> payRate;

double grossPay = getGrossPay(hours, payRate);

cout << "Employee's Total Gross Pay: $" << grossPay << endl;

cout << endl;

} //end while

cout << "Enter next employee's number of hours worked: ";

cin >> hours;

cout << " Enter nexts employee's hourly pay rate: ";

cin >> payRate;

cin >> dummy;

return 0;

} // end main function

double getGrossPay(int hours, double payRate)

{

double grossPay = 0.0;

if (hours >= 1 && hours <= 37)

{

grossPay = hours * payRate;

}

else

if (hours >= 38 && hours <= 50)

{

grossPay = (hours - 37) * (payRate * 1.5) + (37 * payRate);

}

else

if (hours >= 51)

{

grossPay = (hours - 50) * (payRate * 2) + (37 * payRate) + (13 * (payRate * 1.5));

}

return grossPay;

// end if

// end if

//end if

} //

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!