In: Computer Science
C++
write a program that asks the user to enter the hours and rate then calculate the gross pay for an employee, the program should test if the hours are regular (40), any hour more than 40 should be paid with the overtime rate: 1.5*rate. The program should ask repeatedly the user if he/she wants to continue: y or n, if the user types y, then the program should ask for the hours and rate for another employee then display the grosspay. When the user type n, then the program stops.
C++ code:
#include <iostream>
using namespace std;
int main()
{
//initializing pay rate and number of hours
int hours,payRate;
//initializing choice as y
char choice='y';
//looping till user enter 'n'
while(choice=='y'){
//asking for number of hours
cout<<"Enter the number of hours: ";
//accepting it
cin>>hours;
//asking for rate for employee
cout<<"Enter the rate for employee: ";
//accepting it
cin>>payRate;
//checking if number of less than or equal to 40
if(hours<=40)
//printing gross pay
cout<<"The gross pay is
"<<hours*payRate<<endl;
else
//printing gross pay
cout<<"The gross pay is
"<<40*payRate+(hours-40)*payRate*1.5<<endl;
//asking for number of hours
cout<<"Do you wish to continue:";
//accepting it
cin>>choice;
}
return 0;
}
Screenshot:
Input and Output: