prévu l'expression d'erreur sur l'instruction if else

Quelqu'un pourrait-il expliquer pourquoi fait-il prévu d'expression erreur après le "else"? Je pensais que je faisais tout droit.

merci

#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;
  • Vous devez placer plusieurs instructions dans un {} pour if {} else {}.
  • À l'aide d'un décent, l'éditeur qui l'aide avec l'indentation permettrait d'éviter cette erreur. Le w = 0.06*… ligne et tous les suivants choses seraient outdented et, évidemment, à l'extérieur de la if, et vous savez que quelque chose clochait avant même eu le else.
  • Et z= 16.78x; est une erreur de syntaxe; as-tu veux dire z = 16.78 * x;?
InformationsquelleAutor user2205899 | 2013-06-15