0

Halloween_Candy(Code_Coach_Problem)

I made a code to solve the halloween candy problem. It passed the first two tests but failed in the remaining 3 test cases. As they are hidden,I can't understand what's wrong with my code. My_code: #include <stdio.h> int main() { int houses; float a,b; scanf("%d", &houses); if(houses>=3){ a=(float)2/houses; b=(float)a*100; printf("%0.0f",b); } return 0; }

1st Dec 2021, 4:47 AM
Phantom713
Phantom713 - avatar
3 Antworten
+ 7
Output should be rounded up to the nearest integer. #include <math.h> ... printf("%0.0f",ceil(b))
1st Dec 2021, 7:54 AM
Simba
Simba - avatar
+ 1
Ceil rounds float up to the next int.
3rd Dec 2021, 5:15 AM
Joseph Fruin
Joseph Fruin - avatar
0
Simba It worked! But how did it worked!? What is the use of ceil!?
1st Dec 2021, 1:52 PM
Phantom713
Phantom713 - avatar