Write compile and test a C program that uses a loop to calcu

Write, compile, and test a C++ program that uses a loop to calculate and display each employee’s weekly pay and the accumulated total pay for the company.  The program will first ask the user for the number of employees. It will then ask for the number of hours and rate of pay for each employee and display the calculated pay for each employee.  

EXAMPLE RUN (user input appears in blue and bold):

Enter number of employees:  3


Hours: 5

Rate (in dollars):  4.00
Pay is $20.00

Hours: 6

Rate (in dollars):  5.00
Pay is $30.00

Hours: 1.5

Rate (in dollars):  10.00
Pay is $15.00

All employees processed.

Total payroll is $65.00

Format Manipulators:    setw (  ),    setprecision (   ),  setiosflags(ios::showpoint), setiosflags(ios::fixed), setiosflags(ios::scientific), setiosflags(ios::left), setiosflags(ios::right).

Make sure:

(i)    Follow “program template” guidelines for all program documentation and output requirements.
(ii)   Declare all variables using the appropriate data types as indicated by the problem.

(iii)  All results should be displayed with two decimal place accuracy.

Solution


/*
C++ program to determine pay for each employee.
*/

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
int main()
{
int totalEmployees;
double hours;
double rate;
double pay;
double totalPay = 0;

cout << \"Enter number of employees: \";
cin >> totalEmployees;
cout << endl << endl;


for (int i = 0; i < totalEmployees; ++i)
{
cout << \"Hours: \";
cin >> hours;

cout << \"Rate (in dollars): \";
cin >> rate;

pay = hours*rate;
totalPay = totalPay + pay;

cout << \"Pay is $\" << fixed <<setprecision(2) << pay << endl << endl;
}
  
cout << \"All employees processed.\ \";
cout << \"Total payroll is $ \" << fixed <<setprecision(2) << totalPay << endl << endl;
return 0;
}

/*
output:

Enter number of employees: 3


Hours: 5
Rate (in dollars): 4.00
Pay is $20.00

Hours: 6
Rate (in dollars): 5.00
Pay is $30.00

Hours: 1.5
Rate (in dollars): 10.00
Pay is $15.00

All employees processed.
Total payroll is $ 65.00

*/

Write, compile, and test a C++ program that uses a loop to calculate and display each employee’s weekly pay and the accumulated total pay for the company. The p
Write, compile, and test a C++ program that uses a loop to calculate and display each employee’s weekly pay and the accumulated total pay for the company. The p

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site