Simple Problem, but can't figure out

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
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 
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
Topic archived. No new replies allowed.