无法在最后添加我的c ++程序。

时间:2017-01-04 22:15:58

标签: c++

我正在尝试让我的程序添加所有开关案例输入。在运行它时,我让它要求我输入一个Case#((1-4)和除了那些4之外的任何其他数字将给你一个错误代码),同时保留生成的输入的日志。但是,当我想以(-1)结束时,它只是停止工作,反对给我一个我给出的所有注册输入的摘要。这就是我到目前为止所做的。

#include <iostream>
#include <iomanip> 
using namespace std;

int main()
{
int paycode = 0;
double weeklySalary, hourlySalary, grossSales, payPerItem, totalPay;
int hours, items;

cout << "Enter paycode for employee (-1 to end): ";
cin >> paycode;

while (paycode != -1)
{
    switch (paycode)
    {
        case 1:
            cout << "Enter weekly salary for manager: ";
            cin >> weeklySalary;
            totalPay = weeklySalary;
            break;
        case 2:
            cout << "Enter hourly salary for hourly worker: ";
            cin >> hourlySalary;
            cout << "Enter number of hours worked: ";
            cin >> hours;
            if (hours <= 40)
                totalPay = hours * hourlySalary;
            else
                totalPay = 40 * hourlySalary + (hours - 40) * hourlySalary * 1.5;
            break;
        case 3:
            cout << "Enter gross sales for comission worker: ";
            cin >> grossSales;
            totalPay = 250 + grossSales * 0.057;
            break;
        case 4:
            cout << "Enter number of produced items for pieceworker: ";
            cin >> items;
            cout << "Enter pay for each item: ";
            cin >> payPerItem;
            totalPay = items * payPerItem;
            break;
        default:
            cout << "Wrong input!" << endl;
            totalPay = 0;
            break;              
    }
    cout    << setiosflags(ios::fixed);
    cout    << setiosflags(ios::showpoint);
    cout    << setprecision(2);
    cout << "Total weekly pay is: $ " << totalPay << endl << endl;
    cout << "Enter paycode for next employee (-1 for exit): ";
    cin >> paycode;
}
return 0;
}

0 个答案:

没有答案