+ 1

Why is my code not working

The code is actually for paint costs coach code problem. It should take in the number of paints and multiply it by 5. Then add the cost of canvas and brush which is 40. It should then add a tax of 10% and print out the cost to the nearest integer. My code didn't pass case 3 and 4. I decided to add 1 to the answer, it then passed 3 and 4 but failed others. So I'm confused as to whether I'm using round() wrong. Like maybe for cases 3 and 4, its supposed to round up but round() rounds down instead. And that's why adding 1 works. I need help https://code.sololearn.com/caT9P9r6CWbn/?ref=app

27th Dec 2020, 1:55 PM
Sekiro
Sekiro - avatar
5 Answers
+ 4
On like 12 You are performing division between 2 integers so the result will also be in integer and not float. So in order to fix it, just caste either numerator or denominator to float (already mentioned by Hima ) Here's fix👇 https://code.sololearn.com/c43L7fI9eabP/?ref=app
27th Dec 2020, 2:03 PM
Arsenic
Arsenic - avatar
+ 2
c=b/10.0; Change your line 12 with this You see 9/10 =0 but (9/10.0)!=0 in C/C++
27th Dec 2020, 2:00 PM
Hima
Hima - avatar
+ 1
Arsenic Thanks for the explanation.đŸ‘ŒđŸŸ
27th Dec 2020, 2:05 PM
Sekiro
Sekiro - avatar
0
Hima It worked. Thanks. But please why didn't 10 work? Why did we have to use 10.0?
27th Dec 2020, 2:03 PM
Sekiro
Sekiro - avatar
0
There must be a case similar to what I have mentioned where it is failing . Tarvs
27th Dec 2020, 2:04 PM
Hima
Hima - avatar