我是C++的新手,一直致力于一项任务
好吧这样运行,但它不会在窗口出现时进行计算我输入AB或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;
}
Run Code Online (Sandbox Code Playgroud)
你在第一个if(在行尾)之后有一个分号.删除它,你就完成了.
if (authorLevel = 'C');
Run Code Online (Sandbox Code Playgroud)
应该
if (authorLevel == 'C')
Run Code Online (Sandbox Code Playgroud)
正如其他人所指出的,还有其他额外的分号和错误.小心!