提问者:小点点

刚接触C++的人不知道我哪里出错了。应为不合格-ID:23


我是C++的新手,我看过类似的问题,不知道哪里出了问题。我知道这很简单,但我只是做一些随机的事情,希望它能运行。第23行的分号有错误。应为不合格-ID:23。我想它和分号有关,但我不知道它有什么问题。

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;
int main()
{
    const double income_limit_mo = 37750; // max income for missouri
    const double income_limit_ks = 34500; // max income for kansas
    const double credit_rate = 0.0975; // tax credit of 9.75%
    char homeowner_status;
    string state;
    double income;
    double credit_amount;

    cout << "Are you a homeowner [Y/N]? ";
    cin >> homeowner_status;
    cout << endl;

    if (homeowner_status == 'Y' || homeowner_status == 'y')
        cout << "Resident State [MO or KS]:  ";
        cin >> state;}
{
        if (state == "MO" || state == "Mo" || state == "mo")
            {cout << "  Amount of annual income: ";
            cin >> income;

             if (income <= income_limit_mo)
                { credit_amount = (income * credit_rate);
                cout << "Allowed amount of credit: $ ";
                cout << credit_amount;}
            else
                cout << "Applicant ineligible. Income too high";}

        else if (state == "KS" || state == "Ks" || state == "ks")
            {cout << "Amount of annual income: ";

             if (income <= income_limit_ks)
                {credit_amount = (income * credit_rate);
                cout << "Allowed amount of credit: $ ";
                cout << credit_amount;}
             else
                cout << "Applicant ineligible. Income too high";}

        else
            cout << "Applicant ineligible. Not Missouri or Kansas resident.";
    else
        cout << "Applicant ineligible. Not a homeowner."









    




    return 0;
}

共1个答案

匿名用户

在第48行的末尾缺少了一个分号,但是你也有一个花括号的问题。这是我在修正后得到的结果,但是要注意你的if/else逻辑。我建议使用ALWALLE{和}花括号,即使对于1行if/else语句也是如此。

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;
int main() {
    const double income_limit_mo = 37750;  // max income for missouri
    const double income_limit_ks = 34500;  // max income for kansas
    const double credit_rate = 0.0975;  // tax credit of 9.75%
    char homeowner_status;
    string state;
    double income;
    double credit_amount;

    cout << "Are you a homeowner [Y/N]? ";
    cin >> homeowner_status;
    cout << endl;

    if (homeowner_status == 'Y' || homeowner_status == 'y') {
        cout << "Resident State [MO or KS]:  ";
        cin >> state;

        if (state == "MO" || state == "Mo" || state == "mo") {
            cout << "  Amount of annual income: ";
            cin >> income;

            if (income <= income_limit_mo) {
                credit_amount = (income * credit_rate);
                cout << "Allowed amount of credit: $ ";
                cout << credit_amount;
            }
            else
                cout << "Applicant ineligible. Income too high";
        }

        else
            if (state == "KS" || state == "Ks" || state == "ks") {
                cout << "Amount of annual income: ";

                if (income <= income_limit_ks) {
                    credit_amount = (income * credit_rate);
                    cout << "Allowed amount of credit: $ ";
                    cout << credit_amount;
                }
                else
                    cout << "Applicant ineligible. Income too high";
            }
            else
                cout << "Applicant ineligible. Not Missouri or Kansas resident.";
    }
    else
        cout << "Applicant ineligible. Not a homeowner.";

    return 0;
}

相关问题


MySQL Query : SELECT * FROM v9_ask_question WHERE 1=1 AND question regexp '(接触|c++|的人|不知道|错了|应为|不合格|id)' ORDER BY qid DESC LIMIT 20
MySQL Error : Got error 'repetition-operator operand invalid' from regexp
MySQL Errno : 1139
Message : Got error 'repetition-operator operand invalid' from regexp
Need Help?