#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int employeeNum = 0; int totalEmployees = 0;
double hourlyRate = 0.0; double totalhoursWork = 0.0;
double hoursWork = 0.0; double totalnetPay = 0.0;
double grossPay = 0.0; double averagehoursWork = 0.0;
double netPay = 0.0; double totalwithHoldings = 0.0;
double withHoldings = 0.0; double overTime = 0.0;
int x = 0;
while(employeeNum!= 9999)
{
cout <<" Enter Employee Number (9999 to Stop):";
cin >> employeeNum;
if(employeeNum ==9999)
break;
cout <<"Enter hourly rate:";
cin >> hourlyRate;
cout <<"Enter hours worked:";
cin >> hoursWork;
cout <<"Employee Number:"<<employeeNum << endl;
if(hoursWork <= 40)
{
grossPay= hoursWork * hourlyRate;
cout <<" Gross Weekly Pay=" << fixed <<setprecision(2)<< grossPay << endl;
}
else if (hoursWork > 40)
{
overTime = hoursWork-40;
grossPay = (overTime * 1.5 + 40)* hourlyRate;
cout <<" Gross Weekly Pay="<< fixed <<setprecision(2)grossPay << endl;
}
if( grossPay > 1000.00)
{
withHoldings= grossPay*0.28;
}
else if( grossPay <= 1000.00)
{
withHoldings= grossPay*0.21;
}
netPay= grossPay-withHoldings;
cout <<" Net Weekly Pay="<<fixed << setprecision(2) << netPay << endl;
totalhoursWork+=hoursWork;
totalnetPay+=netPay;
totalwithHoldings+= withHoldings;
averagehoursWork= totalhoursWork/totalEmployees;
totalEmployees++;
}
averagehoursWork= totalhoursWork/totalEmployees;
for (int x = 1; x < 44; x = x + 1)
cout <<"*";
cout << endl;
cout <<"Total Employees Entered=" << totalEmployees << endl;
cout <<" Total Hours Worked="<< fixed << setprecision(2) << totalhoursWork << endl;
cout <<" Average Hours Worked="<< fixed << setprecision(2) << averagehoursWork << endl;
cout <<" Total Net Pay="<<fixed << setprecision(2) << totalnetPay << endl;
cout <<" TotalwithHoldings=" << fixed << setprecision(2)<< totalwithHoldings << endl;
for (int x = 1; x < 44; x = x + 1)
cout <<"*";
cout << endl;
system("pause");
return 0;
}
每小时费率必须高于 7.25 美元且低于 100.00 美元。Hours working 必须大于 0 且小于 120。如果用户输入无效数据显示和适当的错误信息并要求用户重新输入。这部分我应该使用什么语句,我应该把它放在哪里?