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; }

6th Feb 2023, 4:54 AM
noob
noob - avatar
6 Answers
+ 2
Change "round(percent)" to "ceil(percent)"... it will pass all test cases you should read more on `ceil` and why it is the correct function to solve this problem
6th Feb 2023, 8:04 AM
Mirielle
Mirielle - avatar
+ 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)
6th Feb 2023, 7:27 AM
Scott D
Scott D - avatar
+ 2
Testcase are hidden for everyone, ig.
6th Feb 2023, 1:13 PM
Mirielle
Mirielle - avatar
+ 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?
6th Feb 2023, 12:54 PM
noob
noob - avatar
+ 1
Mirielle Definitely a more elegant solution than mine.
7th Feb 2023, 9:26 AM
Scott D
Scott D - avatar
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.
6th Feb 2023, 5:58 AM
ArsenicolupinIII