In this exercise, you will create a program that displays the gross pay for one or more employees. If necessary, create a new project named Introductory16 Project, and save it in the Cpp8\Chap10 folder. The program should allow the user to enter the number of hours the employee worked and his or her hourly pay rate. 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 employee’s overtime pay, if applicable. Enter your C++ instructions into a source file named Introductory16.cpp. Also enter appropriate comments and any additional instructions required by the compiler. Test the application appropriately. (Hint: If an employee earns $10 per hour and works 37 hours, the gross pay is $370.00. If he or she works 38 hours, the gross pay is $385.00. If he or she works 51 hours, the gross pay is $585.00.)
main.cpp
#include <iostream>
using namespace std;
void grossPay(int hours, int paid){
double total;
if(hours <= 37){
total = hours * paid;
}
else if (hours >= 38 && hours <=50){
total += paid * 37;
total += (paid*1.5)*(hours-37);
}
else{
total += paid * 50;
total += (paid*2)*(hours-50);
}
cout<<"Gross Pay: $"<<total<<endl;
}
int main() {
int hours, paid;
cout<<"Enter number of hours worked: "<<endl;
cin>>hours;
cout<<"Enter the amount paid for one hour: "<<endl;
cin>>paid;
grossPay(hours,paid);
return 0;
}
Output:
Get Answers For Free
Most questions answered within 1 hours.