-4
#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。如果用户输入无效数据显示和适当的错误信息并要求用户重新输入。这部分我应该使用什么语句,我应该把它放在哪里?

4

2 回答 2

0

您可以使用 Cin 和 Cout 进行输入和输出,只需使用 do While 循环

 int employeeNum = 0;

            do
            {
                Console.WriteLine("enter Employee /Number 9999 to STOP");
                employeeNum = int.Parse(Console.ReadLine());

                if (employeeNum == 9999)
                    break;

                Console.WriteLine("enter hourly rate ");
                double hourRate = Double.Parse(Console.ReadLine());




            } while (employeeNum != 9999);
于 2013-04-22T13:35:08.920 回答
0

你可以这样做:

cout << "Enter hourly rate:";
cin >> hourlyRate;
while (hourlyRate <= 7.25 || hourlyRate >= 100) {
    cout << endl << "Reenter hourly rate (must be in (7.25 - 100))";
    cin >> hourlyRate;
}

但是stackoverflow不是为别人做你的功课。

于 2013-04-22T14:09:20.200 回答