Computer Science Canada Problem compiling and getting "expected primary-expression before "else" error |
Author: | Creatlv3 [ Wed Feb 10, 2010 4:03 am ] | ||||
Post subject: | Problem compiling and getting "expected primary-expression before "else" error | ||||
I am writing a program for my class and it needs to incorporate the cin.fail() command which i have and i believe it works fine, the problem arises with my if/else statements. the code is as follows
the error message is as follows
I just started taking this class 2 weeks ago and i feel confident about the program being able to work if i can get those else statements to work. Any help would be appreciated Dave |
Author: | Zren [ Wed Feb 10, 2010 4:11 am ] |
Post subject: | RE:Problem compiling and getting "expected primary-expression before "else" error |
It might be that you have semicolons after every while statement. If it's not a problem with the line itself, it's bound to be some lame extra ; or } added/missed somewhere leaving your one level up or down. |
Author: | Creatlv3 [ Wed Feb 10, 2010 4:14 am ] |
Post subject: | Re: Problem compiling and getting "expected primary-expression before "else" error |
yea i solved that problem and was in the middle of re editing the problem i am having, it was a case of too many ;'s now my problem is that my while loops are messing up and not proceeding like they should, any suggestions? |
Author: | Zren [ Wed Feb 10, 2010 4:36 am ] | ||
Post subject: | RE:Problem compiling and getting "expected primary-expression before "else" error | ||
Personally I'd do a do-while loop since the logic needs to run through the code first before needing an error checking. I'm not that adept in C++ really, but from what I can see of cin.fail(), it seems to return a boolean? http://msdn.microsoft.com/en-us/library/71t65ya2%28VS.80%29.aspx Don't do the method in that article though, just read cin.fail() description. So I'm not sure why your doing: while (cin.fail()<0) and while (cin.fail()<'0') So instead try something along the lines of
|
Author: | wtd [ Thu Feb 11, 2010 12:01 am ] | ||
Post subject: | RE:Problem compiling and getting "expected primary-expression before "else" error | ||
Does this compile?
|
Author: | DemonWasp [ Thu Feb 11, 2010 12:24 am ] | ||
Post subject: | RE:Problem compiling and getting "expected primary-expression before "else" error | ||
The problem is that you have:
which isn't valid. If you want to check the condition, use else if. If you don't want to check the condition, remove it. If you want to make the (expected) condition for that block obvious but you also want it to be a simple else, use a comment. |