0
What does " error: 'else' without a previous else " mean?
I'm writing some code for a project on here and i used 8 if statements followed by a single else statements. Which when ran, resulted in the error described. Changed it to 1 if statement, followed by 6 else if, then 1 else statements and I got even more errors? Any ideas as to why this is? What am I missing ? EDIT: I posted the code below it's for the newest sololearn challenge. Sorry I didnt post before, got side tracked a little bit.
8 Answers
+ 4
Ok, the problem is the semicolon ;
You don't need that after braces.
So only put your code in { } and not { };
Secondly, I would recommend a switch/case for this kind of code.
Makes a bit easier in my opinion.
oh, and you don't need to assign x again
in the ifs, use comparison
i.e. if(x==1) for example
+ 9
Can u post ur code here which was causing error ?? In that case, fixing error can be pretty easy....
+ 3
Most likely you will have a syntax error somewhere or wrong scopes.
Could you post this part of your code?
This would make it easier to actually find the error.
Also as a hint:
- Copy the part, build a small program containing only this part and try to debug it.
- comment out the part in question and successively de-comment it again to check, when the error first appears.
+ 1
~ swim ~ omg thank you!!!
+ 1
Thanks guys for the suggestions
0
I just posted the entirety of the code. Feel free to give it a look