0

Halloween Candy

I passed 2 tests but others are failed

26th Jul 2023, 4:42 PM
Aakash Gupta
Aakash Gupta - avatar
15 odpowiedzi
+ 2
#include <stdio.h> #include <math.h> int main() { int houses; scanf("%d", &houses); //your code goes here int c =ceil((100.00/houses)*2); printf("%d",(c) ); return 0; }
27th Jul 2023, 7:02 PM
Aweneg Rooney
Aweneg Rooney - avatar
+ 3
Aakash Gupta the code converts from integer to float after doing an integer division. It is losing precision in the integer division. Try: float p = 2.0/houses; //float division
26th Jul 2023, 10:13 PM
Brian
Brian - avatar
+ 3
I see another requirement that needs to be addressed: "Output Format A percentage value rounded up to the nearest whole number." Use the math library ceil function on the final output value. That will round up.
27th Jul 2023, 5:36 AM
Brian
Brian - avatar
+ 3
Here is the solution
27th Jul 2023, 7:01 PM
Aweneg Rooney
Aweneg Rooney - avatar
+ 2
Sorry, I hit send accidentally while in the middle of typing. I finished editing. Now you may read my complete response above.
27th Jul 2023, 5:58 AM
Brian
Brian - avatar
+ 1
Aakash Gupta Can you share your code?
26th Jul 2023, 4:51 PM
Junior
Junior - avatar
0
#include <stdio.h> int main() { float houses; scanf("%f", &houses); //your code goes here if(houses>=3){ float p = 2/houses; float percent = p*100; printf("%.f",percent); } return 0; }
26th Jul 2023, 4:53 PM
Aakash Gupta
Aakash Gupta - avatar
0
Nothing changes.. Brian😅
27th Jul 2023, 3:50 AM
Aakash Gupta
Aakash Gupta - avatar
0
What?
27th Jul 2023, 5:37 AM
Aakash Gupta
Aakash Gupta - avatar
0
Thank You Aweneg Rooney. But Can You Explain the Code and Compare it with mine.. Because Your Code passed all the tests.👍🏻
28th Jul 2023, 3:21 AM
Aakash Gupta
Aakash Gupta - avatar
0
The difference is th ceil I rounded all my values up
28th Jul 2023, 5:14 AM
Aweneg Rooney
Aweneg Rooney - avatar
0
Can you tell me how i can fill my hearts for more learning 🥲
28th Jul 2023, 5:47 AM
usman tariq
usman tariq - avatar
0
Spend 60 cubes or wait For time break to full your lives again
28th Jul 2023, 5:50 AM
Aakash Gupta
Aakash Gupta - avatar
0
Thank you
28th Jul 2023, 5:51 AM
usman tariq
usman tariq - avatar
0
What?
28th Jul 2023, 4:41 PM
NAMYS ALMABEKOV
NAMYS ALMABEKOV - avatar