0
What's wrong with this code?
Please help me with "Halloween Candy" in challenge. It looks easy but I dont know why this code is incorrect :/ You go trick or treating with a friend and all but three of the houses that you visit are giving out candy. One house that you visit is giving out toothbrushes and two houses are giving out dollar bills. Task Given the input of the total number of houses that you visited, what is the percentage chance that one random item pulled from your bag is a dollar bill? Input Format An integer (>=3) representing the total number of houses that you visited. Output Format A percentage value rounded up to the nearest whole number. https://code.sololearn.com/cPu4b5qXjqYE/?ref=app
6 Respuestas
+ 3
you should have used ceil function from math.h header to round up final value
+ 3
Attach the code what you tried
+ 2
#include <stdio.h>
int main() {
int houses;
int a;
scanf("%d", &houses);
a=200/houses;
//your code goes here
if (200%houses==0)
printf("%d", a);
else
printf("%d", a+1);
return 0;
}
this is without using math header file
0
Nandan Kumar it cannot pass case 3, 4 and 5
0
Nandan Kumar oh, thank you, bro. I thought that %.f rounds up its value 😓