我收到错误,我试图让程序编译,但它在情况x给我一个错误

时间:2014-11-17 22:35:58

标签: c++ menu

这是我的程序,它正在工作,如果我摆脱Case'x'仍然是,但我想要,请帮助我。     #包括     #include

using namespace std;

int main() {

const double tax_rate = .09;
const double ot_rate = 1.5;

string emp1fandlname;

bool keeponmoving=true;

double employee1_ot_hours = 0;
double employee1_reg_hours = 0;
double employee1_pay_rate = 0;

char userinput;

cout << "Welcome to our amazing Payroll Calculator!\n";
cout << "------------------------------------------------------\n";

while (keeponmoving) {
    cout <<"select from the menu below:\n";
    cout <<"<E>nter employee information\n";
    cout <<"<C>alculate pay\n";
    cout <<"E<X>it the program\n";
    userinput = cin.get();
    if (cin.peek() == '\n' ) {
        cin.clear();
        cin.ignore(32768, '\n');
        switch (userinput) {
            case 'E':
                while(true) {
                    cout << "\nEmployee 1 information:\n\nWhat is first employee's first and last    name?\n ";
                    getline(cin, emp1fandlname);
                    if (emp1fandlname.length() > 20)
                        cout << "Name is too long" << endl;
                    else if (emp1fandlname.length() <=1)
                        cout << "Name is too short" << endl;
                    else
                        break;
                }
                while(true) {
                    cout << "Please enter your total regular hours for employee 1:" ;
                    cin >> employee1_reg_hours;
                    if (employee1_reg_hours >= 41)
                        cout << "You have illegal amount of regular hours" << endl;
                    else if (employee1_reg_hours <= 0)
                        cout << "That amount of hours is not possible" << endl;
                    else
                        break;
                }
                while(true) {
                    cout << "Please enter your total overtime hours for employee 1: ";
                    cin >> employee1_ot_hours;
                    if (employee1_ot_hours >= 41)
                        cout << "You have illegal amount of overtime hours" << endl;
                    else if (employee1_ot_hours < 0)
                        cout << "That amount of overtime hours is not possible" << endl;
                    else
                        break;
                }
                while (true) {

                    cout << "Now, enter your normal pay rate for employee 1: $";
                    cin >> employee1_pay_rate;
                    if (employee1_pay_rate >= 200)
                        cout << "That's not even possible" << endl;
                    else if (employee1_pay_rate <= 8)
                        cout << "Thats illegal" << endl;
                    else
                        break;
                }

                break;

            case 'C':

                double employee1_regpay = employee1_reg_hours * employee1_pay_rate;
                double employee1_otpay = employee1_ot_hours * (employee1_pay_rate * ot_rate);
                double employee1_totaltax = (employee1_regpay + employee1_otpay) * tax_rate;
                double employee1_netpay = (employee1_regpay + employee1_otpay) - employee1_totaltax;



                cout << "\nTotal Pay for the Employees is:\n\n";
                cout << setprecision(2) << fixed;

                cout << setw(20) << "Employee Name" << setw(10) << "Total" << setw(10) << "Taxes"    << setw(10) << "Net Pay" << endl; 
                cout << setw(20) << emp1fandlname << setw(10) << static_cast<int>   (employee1_regpay + employee1_otpay+0.5) << setw(10) << static_cast<int>(employee1_totaltax+0.5) <<    setw(10) << static_cast<int>(employee1_netpay+0.5) << endl;
                break;

                                }
            case 'X':
                keeponmoving = false;
                break;
        //default:
                cout << "Invalid entry, please choose from the following: E, C or X. \n";
            }


            {
                cin.clear();
                cout << "Invalid entry, please choose from the following: E, C or X. \n";
            }
            }
                //end of menu



                return 0;
        }
}}

我在“X”的情况下收到错误,程序不接受它。请帮我。我使用XCODE编译代码。

1 个答案:

答案 0 :(得分:2)

你有一个迷路}

                            }
        case 'X':
相关问题