+ 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; }
3 Respuestas
+ 5
Just before return 0;
You did a mistake for which the error was occuring.
It should be
printf("%d", pies);
Not
printf(pies);
+ 4
Parth Shendge
Just check
apples = fruit / 2;
if (apples >= 3) {
printf("%d", apples / 3);
} else {
printf("%d", 0);
}
+ 3
Oh ! I have left c programming from too long and I was learning java . That's why I forgot this. Thanks