0

Whats wrong with this? Im newbie, and compiler says there is no if before else. Thanks for any advice.

#include <iostream> using namespace std; int main() { int siblings, popsicles; //take input cin>>siblings ; cin>>popsicles ; if((popsicles%siblings) == 0);{ cout <<"give away"; else{ cout <<"eat them yourself." } } return 0; }

9th Jan 2021, 1:33 PM
Slimmy Jimmy
Slimmy Jimmy - avatar
6 Antworten
+ 6
The semicolon after the condition of the if statement does not belong there. Furthermore, the else statement is nested inside the if statement, where it should follow after it, i.e. if ( ... ) { ... } else { ... } You are also missing a semicolon after the second output, and I would recommend checking the printed statements match the requirements of the code coach.
9th Jan 2021, 1:37 PM
Shadow
Shadow - avatar
+ 5
Remove ";" behind the if statement. And I think there is a ";" missing in 2nd cout line
9th Jan 2021, 1:37 PM
Lisa
Lisa - avatar
+ 1
Thanks a lot, it worked. I feel kinda retarded considering its popsicles problem xd.
9th Jan 2021, 1:58 PM
Slimmy Jimmy
Slimmy Jimmy - avatar
0
Slimmy Jimmy actually this kind of problem always happen to programmers..even the expert one xD
9th Jan 2021, 2:09 PM
durian
durian - avatar
0
Ok im newbie so im not surprised. I was like in cpp u have to put more braces and semilcon as much as you can, after statements or comments. I probably should learn the basics an then do the problems. xd
9th Jan 2021, 2:15 PM
Slimmy Jimmy
Slimmy Jimmy - avatar
0
Please remove the ; after if statement .. then it will work
11th Jan 2021, 5:06 AM
Sampraad Das
Sampraad Das - avatar