[Question] Paint Cost | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

[Question] Paint Cost

Pls any idea on this? https://code.sololearn.com/cDDHUPfC63TF/?ref=app

30th Jul 2020, 5:18 PM
BRYAND CHE
BRYAND CHE - avatar
14 Answers
+ 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; }
1st Aug 2020, 10:47 AM
Khalid Shaikh
Khalid Shaikh - avatar
+ 3
Why there are 2 int main functions, also the cost must be rounded off to a nearest whole number.
30th Jul 2020, 5:27 PM
Sanjyot21
Sanjyot21 - avatar
+ 2
Expected output: "[...] rounded up to the nearest whole number."
30th Jul 2020, 5:20 PM
Sandra Meyer
Sandra Meyer - avatar
+ 2
I think that's just an copy & paste error with those 2 mains and imports/includes.
30th Jul 2020, 5:28 PM
Sandra Meyer
Sandra Meyer - avatar
+ 2
Sandra Meyer may be that can be copy paste error, but that will surely cause an error
30th Jul 2020, 5:32 PM
Sanjyot21
Sanjyot21 - avatar
+ 2
Thanks I've updated it, but no change
30th Jul 2020, 8:53 PM
BRYAND CHE
BRYAND CHE - avatar
+ 2
Sandra Meyer Pls How should I round the output to the nearest whole number
30th Jul 2020, 8:55 PM
BRYAND CHE
BRYAND CHE - avatar
+ 2
Sandra Meyer Did exactly what you said but no change https://code.sololearn.com/cDDHUPfC63TF/?ref=app
30th Jul 2020, 10:21 PM
BRYAND CHE
BRYAND CHE - avatar
+ 1
#include <math.h> And then (int) round(value)
30th Jul 2020, 9:34 PM
Sandra Meyer
Sandra Meyer - avatar
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.
30th Jul 2020, 10:36 PM
Sandra Meyer
Sandra Meyer - avatar
0
Here's it but still got 3 cases https://code.sololearn.com/cDDHUPfC63TF/?ref=app
30th Jul 2020, 10:56 PM
BRYAND CHE
BRYAND CHE - avatar
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).
30th Jul 2020, 10:59 PM
Sandra Meyer
Sandra Meyer - avatar
0
BRYAND CHE Use ceil function from math library Use #include <math.h> to include math library. Then x=ceil(cost)
31st Jul 2020, 4:51 AM
Sanjyot21
Sanjyot21 - avatar
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; }
31st Jul 2020, 5:11 AM
Sanjyot21
Sanjyot21 - avatar