Simple Problem, but can't figure out
II15X (36)
Dec 31, 2008 at 6:42am UTC
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 Dec 31, 2008 at 7:07am UTC
bluezor (298)
Dec 31, 2008 at 8:44am UTC
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)
Jan 1, 2009 at 12:50am UTC
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 Jan 1, 2009 at 12:52am UTC
Topic archived. No new replies allowed.