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.

12th Apr 2019, 12:19 PM
Kirsten Leonard
Kirsten Leonard - avatar
8 ответов
+ 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
12th Apr 2019, 12:39 PM
Matthias
Matthias - avatar
+ 9
Can u post ur code here which was causing error ?? In that case, fixing error can be pretty easy....
12th Apr 2019, 12:35 PM
Arushi Singhania
Arushi Singhania - avatar
+ 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.
12th Apr 2019, 12:34 PM
Matthias
Matthias - avatar
+ 1
~ swim ~ omg thank you!!!
12th Apr 2019, 12:47 PM
Kirsten Leonard
Kirsten Leonard - avatar
+ 1
Thanks guys for the suggestions
12th Apr 2019, 12:48 PM
Kirsten Leonard
Kirsten Leonard - avatar
12th Apr 2019, 12:35 PM
Kirsten Leonard
Kirsten Leonard - avatar
0
I just posted the entirety of the code. Feel free to give it a look
12th Apr 2019, 12:36 PM
Kirsten Leonard
Kirsten Leonard - avatar