0
( NEED HELP ) Halloween candy
I’m trying to solve this challenge but it keep telling me to fix the bug. Can you tell me where is the bug? #include <stdio.h> #include <math.h> int main() { float percent; int part=2; int houses; scanf("%d", &houses); percent = (float) part/houses*100; int rounded_percent = round(percent); printf("%d", rounded_percent); return 0; }
6 Respostas
+ 4
noob
You almost have it. There's a small rounding issue with this line:
int rounded_percent = round(percent);
One way to fix it is to add a small bit to round(percent) example:
round(percent + .____ ).
But it's a very specific amount!
(<1 and >0)
+ 1
thank you so much. i did it. i have never heard of this ceil() function before. Btw, is it only me or most of the test case is hidden?
+ 1
Mirielle
Definitely a more elegant solution than mine.
0
The code seems to be missing information on what the houses and part variables represent in the context of the Halloween candy challenge. Based on the code, the program calculates the percentage of part divided by houses and rounds the result to the nearest integer. It's not possible to determine where the bug is without further context and information on what the desired outcome is.