Trouble with Halloween Candy | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Trouble with Halloween Candy

I can't solve this exercise. If i find the solito for case 1-2 It isn't right for the other cases and the other Way around.

9th Mar 2021, 8:30 AM
Cristopher Ricciotti
Cristopher Ricciotti - avatar
6 Answers
+ 3
Output should be rounded up to the nearest integer. So you need to use ceil() for both conditions :) if (final >= .5){ printf("%.f", ceil(output)); } else{ printf("%.f", ceil(output)); }
9th Mar 2021, 8:47 AM
Simba
Simba - avatar
+ 3
Yup! It rounds up to the nearest integer. Check it out for reference https://code.sololearn.com/cWf030i39pru/?ref=app
9th Mar 2021, 8:55 AM
Simba
Simba - avatar
+ 1
Thank you 🙏
9th Mar 2021, 9:04 AM
Cristopher Ricciotti
Cristopher Ricciotti - avatar
+ 1
Cristopher Ricciotti Try this maybe help you: #include <stdio.h> #include <math.h> int main() { int houses; scanf("%i", &houses); if(houses>=3){ printf("%i",(int)ceil(200.0/houses)); } return 0; } Happy coding 👍😃
9th Mar 2021, 9:27 PM
❤️😍Prerana😍❤️
❤️😍Prerana😍❤️ - avatar
0
#include <stdio.h> #include <math.h> int main() { float houses; scanf("%f", &houses); float dollar = 2; float output = (dollar / houses)*100; int res; res = (int)output; float final; final = output - res; if (final >= .5){ printf("%.f", ceil(output)); } else{ printf("%.f", floor(output)); } return 0; } Actually this Is the last version
9th Mar 2021, 8:42 AM
Cristopher Ricciotti
Cristopher Ricciotti - avatar
0
But ceil() should round up to the biggest, or not? 🤔
9th Mar 2021, 8:49 AM
Cristopher Ricciotti
Cristopher Ricciotti - avatar