分号/字符串常量错误

时间:2018-01-10 18:17:49

标签: c++

好吧,伙计们,我的问题很简单 当我尝试构建此代码时,我得到2个错误,在第45行和第55行中它们都是错误:预期;字符串常量之前。 为了澄清,第45和第55行在最后一个cout中的情况3和4中一直向下,并且我在行前面放置星星以明确我的意思!没有字符串常量所以我只是困惑。请帮忙。

#include <iostream> <cmath>

using namespace std;

int main()
{
    bool goOn;
    do
    {
        goOn = false;
        cout <<"Press 1 to add" <<endl;
        cout <<"Press 2 to subtract" <<endl;
        cout <<"Press 3 to multiply" <<endl;
        cout <<"Press 4 to divide" <<endl;
        cout <<"Pres 5 to end the program" <<endl;
        int num;
            cin >>num;
            switch (num)
            {
                case 1: //adding
                    int sum;
                    int add1;
                    int add2;
                        cout <<"What do you want to add? Type 2 Numbers!" <<endl;
                        cin >>add1 >>add2;
                        sum = add1+add2;
                        cout <<"Sum is:" <<sum <<endl;
                break;
                case 2: //subtracting
                    int dif;
                    int sub1;
                    int sub2;
                        cout <<"What do you want to subtract? Type 2 Numbers!" <<endl;
                        cin >>sub1 >>sub2;
                        dif = sub1-sub2;
                        cout <<"Difference is" <<dif <<endl;
                break;
                case 3: //multiplying
                    int prod;
                    int fac1;
                    int fac2;
                        cout <<"What do you want to multiply?" <<endl;
                        cin >>fac1 >>fac2;
                        prod = fac1*fac2;
                        **cout <<"Done!" <<fac1 " multiplied by " <<fac2 " equals " <<prod <<endl;
                case 4: //dividing
                    int quot;
                    int divid;
                    int divis;
                    int rem;
                        cout <<"What do you want to divide, and with what? Dividend first, then divisor!" <<endl;
                        cin >>divid >>divis;
                        quot = divid/divis;
                        rem = divid%divis;
                        **cout <<"Done!" <<divid " divided by " <<divis " equals " <<quot " with a remainder of " <<rem <<endl;
                break;
                case 5: //ending the program
                    cout <<"Goodbye" <<endl;
                return 0;
                default:
                    cout <<"Bad input" <<endl;
                break;
            }
        } while (goOn == false);
}

1 个答案:

答案 0 :(得分:0)

cout <<"Done!" <<fac1  " multiplied by " <<fac2 " equals " <<prod <<endl;

应该是

cout <<"Done!" <<fac1 << " multiplied by " <<fac2 <<" equals " <<prod <<endl;

cout <<"Done!" <<divid " divided by " <<divis " equals " <<quot " with a remainder of " <<rem <<endl;

应该是

cout <<"Done!" <<divid << " divided by " <<divis << " equals " <<quot <<" with a remainder of " <<rem <<endl;

即。缺少&lt;&lt;