0
Need help with C challenge
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. Sample Input 4 Sample Output 50 For me, the hidden test cases are failing and I don't know why https://code.sololearn.com/cFan4RT8MK2C/?ref=app
4 Respostas
+ 4
Output should be rounded up to the nearest integer. So you need to use ceil() instead of round ()
printf("%i",(int)ceil(((double)200/(double)houses)))
+ 1
Simba yeah it worked, thank you. Why doesn't "round" work here? If the number is 50.1, ceil function rounds it to 51, but it really has to be rounded to 50 right? Then how does ceil work here?
0
Because the definition for ceil() is that it returns ceiling value of x i.e., the smallest integer not less than x.
That's why 50.1 is rounded up to 51 not 50 (50 < 50.1 < 51)
0
Simba yeah I know that. But my doubt is that, isn't the value 50.1 rounded to 50 instread of 51 in this question?