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.
6 odpowiedzi
+ 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));
}
+ 3
Yup!
It rounds up to the nearest integer.
Check it out for reference
https://code.sololearn.com/cWf030i39pru/?ref=app
+ 1
Thank you 🙏
+ 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 👍😃
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
0
But ceil() should round up to the biggest, or not? 🤔