+ 3
[Question] Paint Cost
Pls any idea on this? https://code.sololearn.com/cDDHUPfC63TF/?ref=app
14 RĂ©ponses
+ 10
#include <stdio.h>
#include <math.h>
int main() {
int colors;
scanf("%d", &colors);
printf("%d", (int)round(1.1 * (5 * colors + 40)));
return 0;
}
+ 3
Why there are 2 int main functions, also the cost must be rounded off to a nearest whole number.
+ 2
Expected output: "[...] rounded up to the nearest whole number."
+ 2
I think that's just an copy & paste error with those 2 mains and imports/includes.
+ 2
Sandra Meyer may be that can be copy paste error, but that will surely cause an error
+ 2
Thanks I've updated it, but no change
+ 2
Sandra Meyer
Pls How should I round the output to the nearest whole number
+ 2
Sandra Meyer
Did exactly what you said but no change
https://code.sololearn.com/cDDHUPfC63TF/?ref=app
+ 1
#include <math.h>
And then (int) round(value)
0
You have to round the result BEFORE you assign a temporary result to an integer variable, otherwise you've already produced information loss before you rounded.
0
Here's it but still got 3 cases
https://code.sololearn.com/cDDHUPfC63TF/?ref=app
0
Try all these steps in one command, one line:
tax = 0.10 * (color+brush);
cost= brush + color +tax;
x = round(cost);
OR (alternatively), use float for all the steps before you're rounding the result (but did not try this option).
0
BRYAND CHE
Use ceil function from math library
Use #include <math.h> to include math library. Then x=ceil(cost)
0
BRYAND CHE
Try this code .....
#include <stdio.h>
#include <math.h>
int main() {
int color, brush,tax,cost;
scanf("%d", &color);
brush = 40 ;
color*=5;
tax =ceil( 0.10 * (color+brush));
cost= brush + color +tax;
printf("%d", cost);
return 0;
}