+ 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; }
4 Respostas
+ 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().
+ 3
Hint: there will be searched a percentage chance of 2 in hoses (number).
+ 2
Thank you sir, very much appreciated
+ 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 :)