C++ 错误 'else' 没有前一个 'if'

标签 c++ if-statement output

<分区>

我是 C++ 新手,一直在做作业

好的,这样就可以运行了,但是它不进行计算 当窗口出现时,我输入 A B 或 C 然后是单词的长度 它只是说 pay=0

这是新代码:

#include <iostream>




using namespace std;


char authorLevel;
int numberOfWords, payTotal;
int fixedPayAmount;



int main()
{


cout << "Enter Author Level(A,B,or C):";
char authorLevel;
cin >>authorLevel;

cout << "Enter Length(in words):";
int numberOfWords;
cin >>numberOfWords;

cout << "Pay is: $" << payTotal << endl; 
int payTotal;


cout << "Fixed Pay is:$" << fixedPayAmount << endl;
int fixedPayAmount;

//Calculations for C Level Author


if (authorLevel == 'C')
{

         //If the Number of words is <7500 multiply by 0.08     
              if (numberOfWords <=7500)
                  {
                    payTotal= numberOfWords * 0.08;                     
                  }

        //If the numberOfWords is >7500 to <=8000 pay is fixed 600
                if (numberOfWords >7500 || numberOfWords <= 8000)
                    {
                        fixedPayAmount= 600;

                    }
        //If the numberOfWords is >8000 to <=17500 multiply by 0.075
              if (numberOfWords >8000 || numberOfWords <=17500)     
                    {
                    payTotal= numberOfWords * 0.075;
                    }
        //If the numberOfWords is >17500 to <= 19000 fixed $1313
             if (numberOfWords >17500 || numberOfWords <= 19000)
                    {
                        fixedPayAmount=1313;
                    }
        //If the numberOfWords is >=19000 multiply 0.07
            if (numberOfWords >=19000)
            {
                payTotal= numberOfWords * 0.07;
            }
}

else if (authorLevel== 'A')
    {


         //If the Number of words is <7500 multiply by 0.14     
              if (numberOfWords <=7500)
                  {
                    payTotal= numberOfWords * 0.14;
                    }

        //If the numberOfWords is >7500 to <=8000 pay is fixed $1050
                if (numberOfWords >7500 || numberOfWords <= 8000)
                    {
                        fixedPayAmount= 1050;

                    }
        //If the numberOfWords is >8000 to <=17500 multiply by 0.13125
              if (numberOfWords >8000 || numberOfWords <=17500)     
                    {                                               
                    payTotal= numberOfWords * 0.13125;
                    }
        //If the numberOfWords is >17500 to <= 19000 fixed $2297.75
             if (numberOfWords >17500 || numberOfWords <= 19000)
                    {
                        fixedPayAmount=2297.75;
                    }
        //If the numberOfWords is >=19000 multiply 0.1225
            if (numberOfWords >=19000)
            {
                payTotal= numberOfWords * 0.1225;
            }
    }



    else if (authorLevel== 'B')
    {

         //If the Number of words is <7500 multiply by 0.1  
              if (numberOfWords <=7500)
                  {
                        payTotal= numberOfWords * 0.1;
                    }

        //If the numberOfWords is >7500 to <=8000 pay is fixed $750
                if (numberOfWords >7500 || numberOfWords <= 8000)
                    {
                        fixedPayAmount= 750;

                    }
        //If the numberOfWords is >8000 to <=17500 multiply by 0.09375
              if (numberOfWords >8000 || numberOfWords <=17500)     
                    {
                    payTotal= numberOfWords * 0.09375;
                    }
        //If the numberOfWords is >17500 to <= 19000 fixed $1641.25
             if (numberOfWords >17500 || numberOfWords <= 19000)
                    {
                        fixedPayAmount=1641.25;
                    }
        //If the numberOfWords is >=19000 multiply 0.0875
            if (numberOfWords >=19000)
            {
                payTotal= numberOfWords * 0.0875;
            }
    }


            return 0;
}

最佳答案

在第一个 if 之后(在行尾)有一个分号。删除它,你就完成了。

if (authorLevel =   'C');

应该是

if (authorLevel ==   'C')

正如其他人所指出的,还有其他额外的分号和错误。小心!

关于C++ 错误 'else' 没有前一个 'if',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22179537/

相关文章:

unix - 将命令输出 append 到不带换行符的文件

c++ - make_heap 的意义何在?

c++ - C++中的通用链表

c++ - 如何正确地创建(和分配)仅由 C++ 中的抽象基已知的对象列表?

JavaScript 比较失败

java - 打印两次

powershell - Select-Object cmdlet 中要输出的可变数量的字段

c++ - 来自 std::any 的 std::is_reference

node.js - process.env.NODE_ENV 无论如何都不匹配 'development'

python - Amazon + Django 每12小时出现[Errno 5] Input/output error