What's wrong with my code? Hallowen candy case 3 and so on, i cant complete it | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What's wrong with my code? Hallowen candy case 3 and so on, i cant complete it

#include <stdio.h> int main() { int houses; scanf("%d", &houses); //your code goes here float per_dollar; int testNum, checkNum, roundNum; if (houses >= 3) { per_dollar = (2/(float)houses) * 100; testNum = per_dollar * 10; checkNum = testNum % 10; if(checkNum >= 5){ roundNum = per_dollar; roundNum++; } else { roundNum = per_dollar; } printf("%d",roundNum); } return 0; }

11th Oct 2021, 3:37 PM
lensearfwyn namocatcat
lensearfwyn namocatcat - avatar
4 Answers
+ 3
Unfortunately there is a math problem in accuracy in your calculation of the checkNum. A solution is: testNum = per_dollar * 1000; checkNum = testNum % 1000; Better is to use build in function ceil().
13th Oct 2021, 12:20 PM
JaScript
JaScript - avatar
+ 3
Hint: there will be searched a percentage chance of 2 in hoses (number).
11th Oct 2021, 10:34 PM
JaScript
JaScript - avatar
+ 2
Thank you sir, very much appreciated
13th Oct 2021, 12:31 PM
lensearfwyn namocatcat
lensearfwyn namocatcat - avatar
+ 1
Thank you for the hint sir but can you elaborate it please cuz i don't what you really mean sir thank for helping :)
13th Oct 2021, 3:02 AM
lensearfwyn namocatcat
lensearfwyn namocatcat - avatar