Salary Calculator) Develop a C++ program that uses a while statement to determine the gross pay for each of several employees. The company pays “straight time” for the first 40 hours worked by each employee and pays “time and half” for all hours worked in excess of 40 hours. You are given a list of the employees of the company, the number of hours each employee worked last week and the hourly rate of each employee.
Enter hours worked (1 to end): 39
Enter hourly rate of the employee ($00.00): 1 0.00
Salary is $390.00
Enter hours worked (1 to end): 40
Enter hourly rate of the employee ($00.00): 1 0.00
Salary is $400.00
Enter hours worked (1 to end): 41
Enter hourly rate of the employee ($00.00): 1 0.00
Salary is $41 5.00
Enter hours worked (1 to end): 1
#include < cstdio>
#include < cstdlib>
#include < iostream>
#include < iomanip>
using namespace std;
int main()
{
double totalSalary = 0;
double salary;
double extSalary;
double hours;
double rate;
cout << "Enter hours worked (‐1 to end) : ";
cin >> hours;
while( hours ! = ‐1)
{
cout << "Enter hourly rate of the employee ($00. 00) : ";
cin >> rate;
if( hours <=40 )
{
salary = hours * rate;
cout << "Salary is $" << setprecision( 2 ) << fixed << salary << endl;
}
Your program should input this information for each employee and should determine and display the employee’s gross pay.
Enter hours worked (1 to end): 39
Enter hourly rate of the employee ($00.00): 1 0.00
Salary is $390.00
Enter hours worked (1 to end): 40
Enter hourly rate of the employee ($00.00): 1 0.00
Salary is $400.00
Enter hours worked (1 to end): 41
Enter hourly rate of the employee ($00.00): 1 0.00
Salary is $41 5.00
Enter hours worked (1 to end): 1
Solution:
#include < cstdio>
#include < cstdlib>
#include < iostream>
#include < iomanip>
using namespace std;
int main()
{
double totalSalary = 0;
double salary;
double extSalary;
double hours;
double rate;
cout << "Enter hours worked (‐1 to end) : ";
cin >> hours;
while( hours ! = ‐1)
{
cout << "Enter hourly rate of the employee ($00. 00) : ";
cin >> rate;
if( hours <=40 )
{
salary = hours * rate;
cout << "Salary is $" << setprecision( 2 ) << fixed << salary << endl;
}
else
{
totalSalary = (40*rate) + ((hours‐40) *rate*1. 5) ;
cout << "Salary is $" << setprecision( 2 ) << fixed << totalSalary << endl;
}
cout << "\nEnter hours worked (‐1 to end) : ";
cin >> hours;
}
{
totalSalary = (40*rate) + ((hours‐40) *rate*1. 5) ;
cout << "Salary is $" << setprecision( 2 ) << fixed << totalSalary << endl;
}
cout << "\nEnter hours worked (‐1 to end) : ";
cin >> hours;
}
//for pause
system("PAUSE") ;
return 0;
system("PAUSE") ;
return 0;
Post A Comment:
0 comments: