0
Halloween Candy
I passed 2 tests but others are failed
15 Réponses
+ 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;
}
+ 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
+ 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.
+ 3
Here is the solution
+ 2
Sorry, I hit send accidentally while in the middle of typing. I finished editing. Now you may read my complete response above.
+ 1
Aakash Gupta Can you share your code?
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;
}
0
Nothing changes.. Brian😅
0
What?
0
Thank You Aweneg Rooney. But Can You Explain the Code and Compare it with mine.. Because Your Code passed all the tests.👍🏻
0
The difference is th ceil I rounded all my values up
0
Can you tell me how i can fill my hearts for more learning 🥲
0
Spend 60 cubes or wait For time break to full your lives again
0
Thank you
0
What?