What's wrong with this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

23rd Feb 2020, 12:49 PM
Trần Tân An Nguyễn
Trần Tân An Nguyễn - avatar
6 Answers
+ 3
you should have used ceil function from math.h header to round up final value
23rd Feb 2020, 1:01 PM
Nandan
Nandan - avatar
+ 3
Attach the code what you tried
23rd Feb 2020, 12:54 PM
Nandan
Nandan - avatar
+ 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
24th Feb 2020, 7:05 AM
Aryaman Mishra 🇮🇳
Aryaman Mishra 🇮🇳 - avatar
0
Nandan Kumar it cannot pass case 3, 4 and 5
23rd Feb 2020, 12:58 PM
Trần Tân An Nguyễn
Trần Tân An Nguyễn - avatar
23rd Feb 2020, 1:00 PM
Trần Tân An Nguyễn
Trần Tân An Nguyễn - avatar
0
Nandan Kumar oh, thank you, bro. I thought that %.f rounds up its value 😓
23rd Feb 2020, 1:02 PM
Trần Tân An Nguyễn
Trần Tân An Nguyễn - avatar