-
August 26th, 2009, 02:19 PM
#1
else if problem
Hi
Im fairly new to c++ and ive got stuck with else if statements. I keep getting"error: expected primary-expression before "else""
this is the code, i know its probably really simple i just cant work it out
if (xpgo==1)
xp--;
hp++;
cout<<"You hae added 1 xp to your HP!\n";
else if(xpgo==2)
xp--;
cout<<"You hae added 1 xp to your ATTACK!\n";
at++;
else if(xpgo==3)
xp--;
cout<<"You hae added 1 xp to your DEFENCE!\n";
def++;
else
cout<<"You have input and invalid number please try again\n";
thanks
-
August 26th, 2009, 02:27 PM
#2
Re: else if problem
You need to brace compound statements.
Code:
if (condition )
statement
else
statement
is fine for single statements but when you need compound statements you should do
Code:
if (condition)
{
statement
statement
statement
}
else
{
statement
statement
}
Get Microsoft Visual C++ Express here or CodeBlocks here.
Get STLFilt here to radically improve error messages when using the STL.
Get these two can't live without C++ libraries, BOOST here and Loki here.
Check your code with the Comeau Compiler and FlexeLint for standards compliance and some subtle errors.
Always use [code] code tags [/code] to make code legible and preserve indentation.
Do not ask for help writing destructive software such as viruses, gamehacks, keyloggers and the suchlike.
-
August 26th, 2009, 03:17 PM
#3
Re: else if problem
ahhh thankyou very much i knew itd be simple.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|