Click here to Skip to main content
15,921,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Any suggestions why this statement won't complie if I remark out the else it will complie but without expected results.

Thanks in advance for any help..

This is part of a larger math flashcard program with classes ect... I am using DEV C++ and set an error during compile at the else statements for addition, subtractiom ect... the info I get is expected primary-expression before 'else'



void Flashcard::AdditionQuestion()
{
number1 = getRandom_Number(); // Gets random number
number2 = getRandom_Number(); // Gets random number

sum = number1 + number2;
cout << number1 << "+" << number2 << " = \n";
setUserAnswer();

if ( getUserAnswer() == sum );
{
AdditionCounterCorrect++;
cout << "\n";
CorrectAnswer();

}
else

{
AdditionCounterIncorrect++;
// cout << "Sorry that is WRONG";
cout << "The correct answer is "<< sum << ".\n";
WrongAnswer();
}

return;
}
Posted
Updated 23-Sep-10 12:55pm
v3
Comments
Yusuf 23-Sep-10 18:44pm    
what do you mean by it won't compile? what error do you get?

1 solution

Removing the semicolon at the end of if(getUserAnswer() == sum); might help :)
Next time check that at first :)
cheers,
AR
 
Share this answer
 
Comments
Alecroy 23-Sep-10 18:56pm    
Reason for my vote of 5
Automatic vote of 5 for accepting answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900