Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ if-else语句应为表达式错误_C++_If Statement - Fatal编程技术网

C++ if-else语句应为表达式错误

C++ if-else语句应为表达式错误,c++,if-statement,C++,If Statement,有人能解释一下为什么在“else”之后会出现预期的表达式错误吗?我以为我做的每件事都是对的 多谢各位 #include <iostream> using namespace std; int main() { double x; // number of hours work per week double z; //grosspay double w; //withholding amounts double n; //net pay in

有人能解释一下为什么在“else”之后会出现预期的表达式错误吗?我以为我做的每件事都是对的

多谢各位

#include <iostream>
using namespace std;

int main()
{
    double x; // number of hours work per week
    double z; //grosspay
    double w; //withholding amounts
    double n; //net pay
    int y; // number of dependents


cout<<"how many hours do you work in a week?"<<endl;
cin >> x;


    if(x<=40)
        if(y<3)
            z = 16.78*x;
            w = 0.06*x+0.14*x+0.05*x+10;
            n = z-w;
         cout<< "the grosspay is"<< z <<endl
             <<" the withholding amount is"<< w <<endl
             <<" the netpay is" << n <<endl;
        else---------------------------------------------------------expected expression error
            z= 16.78x;
            w= 0.06*x+0.14*x+0.05*x+10+35;
            n=z-w;
        cout<< "the grosspay is"<< z <<endl
            <<" the withholding amount is"<< w <<endl
            <<" the netpay is" << n <<endl;
    if(x>40)
        if(y<3)
            z= 16.78*40+(x-40*16.78);
            w= 0.06*x+0.14*x+0.05*x+10;
            n=z-w;
        cout<< "the grosspay is"<< z <<endl
            <<" the withholding amount is"<< w <<endl
            <<" the netpay is" << n <<endl;
#包括
使用名称空间std;
int main()
{
double x;//每周工作小时数
双z;//grosspay
双w;//预扣金额
双n;//净工资
int y;//受抚养人的数量

您需要在代码中添加适当的
{}

if(x<=40){
    if(y<3) {
    //^^some code 
    }else{
   //^^some code
     }
}

if(x您需要在代码中添加适当的
{}

if(x<=40){
    if(y<3) {
    //^^some code 
    }else{
   //^^some code
     }
}
if(x使用括号:

   if(x<=40)
   {
       if(y<3)
       {
           z = 16.78*x;
           w = 0.06*x+0.14*x+0.05*x+10;
           n = z-w;
           cout << "the grosspay is"<< z <<endl
             <<" the withholding amount is"<< w <<endl
             <<" the netpay is" << n <<endl;
        }
        else //no more error
        {
            z= 16.78x;
            w= 0.06*x+0.14*x+0.05*x+10+35;
            n=z-w;
            cout<< "the grosspay is"<< z <<endl
            <<" the withholding amount is"<< w <<endl
            <<" the netpay is" << n <<endl;
        }
    }
    if(x>40)
    {
        if(y<3)
        { 
            z= 16.78*40+(x-40*16.78);
            w= 0.06*x+0.14*x+0.05*x+10;
            n=z-w;
            cout<< "the grosspay is"<< z <<endl
              <<" the withholding amount is"<< w <<endl
              <<" the netpay is" << n <<endl;
        }
    }
if(x使用括号:

   if(x<=40)
   {
       if(y<3)
       {
           z = 16.78*x;
           w = 0.06*x+0.14*x+0.05*x+10;
           n = z-w;
           cout << "the grosspay is"<< z <<endl
             <<" the withholding amount is"<< w <<endl
             <<" the netpay is" << n <<endl;
        }
        else //no more error
        {
            z= 16.78x;
            w= 0.06*x+0.14*x+0.05*x+10+35;
            n=z-w;
            cout<< "the grosspay is"<< z <<endl
            <<" the withholding amount is"<< w <<endl
            <<" the netpay is" << n <<endl;
        }
    }
    if(x>40)
    {
        if(y<3)
        { 
            z= 16.78*40+(x-40*16.78);
            w= 0.06*x+0.14*x+0.05*x+10;
            n=z-w;
            cout<< "the grosspay is"<< z <<endl
              <<" the withholding amount is"<< w <<endl
              <<" the netpay is" << n <<endl;
        }
    }

if(xy)对于
if{}else{},您需要在
{}
中包含多个语句
。使用有助于缩进的体面编辑器可以防止此错误。
w=0.06*…
行和以下所有内容最终都会出现凹痕,显然超出了
if
,并且在进入
else
之前,您就知道有什么地方出错了。
z=16.78x;
是一个语法错误;是吗您的意思是
z=16.78*x;
?您需要在
{}
if{}else{}中包含多个语句
。使用有助于缩进的体面编辑器可以防止此错误。
w=0.06*…
行和以下所有内容最终都会出现凹痕,显然超出了
if
,并且在进入
else
之前,您就知道有什么地方出错了。
z=16.78x;
是一个语法错误;是吗你是说
z=16.78*x;