c++ - if else 语句的预期表达式错误

标签 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
    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;

最佳答案

您需要在代码中添加正确的{}

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

关于c++ - if else 语句的预期表达式错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17118979/

相关文章:

c++ - 为什么我不能在另一个函数中定义一个函数?

C++ vector 数据访问

c++ - 使用 g++ 时使用 extern "C"{ 对 C++ 代码的影响

c# - Foreach 循环只验证第一个元素

c# - if语句多个条件和匹配多个值的区别

html - 在 Django if/else 语句中用 CSS 替换图像

c - 如何简化大量的 C if 语句?

c++ - 源代码中的注释

c++ - ofstream variable.open 是否支持预先确定的字符串变量?

php - 在 CSS 中使用 "if/else"改变语言