( NEED HELP ) Halloween candy | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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
4 Answers
+ 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
+ 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