Write an interactive C program that helps a company calculat

Write an interactive C++ program that helps a company calculate weekly payroll for their hourly employees. The program should read in the hourly pay rate of the employee and the number of hours the employee worked that week. If the employee worked 40 hours are less, their weekly pay is their pay rate for each hour worked. If the employee work ed more than 40 hours, but less than or equal to 50 hours, the employee receives time and half for tho se hours over 40. For any hours worked over 50 hou rs, the employee receives double time for those hours only. The program should print the hours worked and the weekly pay. Print all monetary values to 2 decimal places. Make sure you provide identifying text for the information printed.

Solution

Please find the required program along with its output. Please see the comments against each line to understand the step.

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main()
{
double hr,hw;
cout << \"Enter hourly pay rate\" << endl;
cin >> hr; //read employees hourly pay rate
cout << \"Enter no:of hours worked\" << endl;
cin >> hw; //read employee total hours worked
  
double extraPay = 0;
if(hw > 40 && hw < 50){ //determine the extra pay. If hours worked is > 40 but < 50
extraPay = extraPay + ((hw-40) * 1.5 * hr); //add 1.5 of hr rate
}
  
if(hw > 50){ //if hours worked more than 50
extraPay = extraPay + ((hw-50) * 2 * hr); //add 2 of hr rate
}
  
double pay = 0;
if(hw < 40) { //determine the basic pay
pay = hw * hr;
}else {
pay = 40 * hr;
}
  
double totalPay = pay + extraPay; //total pay
  
  
std::cout << std::fixed;
std::cout << std::setprecision(2); //print to 2 decimal places

cout << \"Hours worked : \" << hw << endl;
cout << \"Weekly pay : \" << totalPay << endl;

}

----------------------------------------------------

OUTPUT :

Enter hourly pay rate
20
Enter no:of hours worked
36
Hours worked : 36.00
Weekly pay : 720.00

Enter hourly pay rate
20
Enter no:of hours worked
45
Hours worked : 45.00
Weekly pay : 950.00

Enter hourly pay rate
20
Enter no:of hours worked
56
Hours worked : 56.00
Weekly pay : 1040.00

Write an interactive C++ program that helps a company calculate weekly payroll for their hourly employees. The program should read in the hourly pay rate of the
Write an interactive C++ program that helps a company calculate weekly payroll for their hourly employees. The program should read in the hourly pay rate of the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site