question  Simple Problem, but can't figure out

II15X (27)   Link to this post
Below is part of the code:

1
2
3
4
5
6
if ( x + y == w){
        cout << w << "!\n";
        
    else
        cout << "Wrong\n";
        cin.get(); }


Error:

1
2
21 F:\Programming Prc\Prc 1.cpp
parse error before `else' 



I can't figure out why? I have tried everything and yet nothing.


Edit
Does Windows XP Professional support C++?
Last edited on
bluezor (208)   Link to this post
The new code should be -

1
2
3
4
5
6
7
8
9
if (x + y == w)
{
cout << w << "!\n";
} //you should've ended your curly braces for 'if' statement here
else
{ //start a new braces for 'else' statement here
cout << "Wrong!\n";
cin.get();
} //end for 'else' statement 
modulo51 (7)   Link to this post
Since your if only has one statement for each branch you don't need braces:


if( x+y==w) cout<<w<<"!\n";
else cout<<"wrong!\n";

Last edited on

This topic is archived - New replies not allowed.