Simple Problem, but can't figure out
II15X (27) Nov 21, 2009 at 4:34pm 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 Nov 21, 2009 at 4:34pm UTC
bluezor (208) Nov 21, 2009 at 4:34pm 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) Nov 21, 2009 at 4:34pm 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 Nov 21, 2009 at 4:34pm UTC
This topic is archived - New replies not allowed.