What's wrong with this code ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What's wrong with this code ?

I was trying to solve a challenge but this code isn't working. Challenge name : fruit bowl Code : #include <stdio.h> // only enter an even number as input int main() { int fruit; int apples; int pies; scanf("%d", &fruit); //your code goes here apples = fruit/2; if((apples%3)==1){ apples -= 1; } else if((apples%3)==2){ apples -= 2; } else{ // does nothing } pies = apples/3; printf(pies); return 0; }

28th Mar 2021, 10:23 AM
Parth Shendge
3 Answers
+ 5
Just before return 0; You did a mistake for which the error was occuring. It should be printf("%d", pies); Not printf(pies);
28th Mar 2021, 10:39 AM
Kashyap Kumar
Kashyap Kumar - avatar
+ 4
Parth Shendge Just check apples = fruit / 2; if (apples >= 3) { printf("%d", apples / 3); } else { printf("%d", 0); }
28th Mar 2021, 10:35 AM
A͢J
A͢J - avatar
+ 3
Oh ! I have left c programming from too long and I was learning java . That's why I forgot this. Thanks
28th Mar 2021, 10:41 AM
Parth Shendge