+ 1

I need some help with the "paint costs" problem

I am unable to get all the test cases right using the following code : #include <iostream> #include <cmath> using namespace std; int main() { int numOfColors; cin >> numOfColors; float total = ((40.0 + numOfColors * 5.0) * 1.1); cout << ceil(total); return 0; } Can anyone please help me solving this problem?

19th Dec 2019, 7:01 AM
SHRABON
SHRABON - avatar
3 Answers
+ 1
Tried it but still gets error in testCase #3 and #5
19th Dec 2019, 9:15 AM
SHRABON
SHRABON - avatar
+ 1
Unexpectedly got it right by altering the code a bit : #include <iostream> #include <cmath> using namespace std; int main() { int numOfColors; cin >> numOfColors; float total = ((40 + numOfColors * 5) * 1.1f); if (total == (int)total) { cout << (int)total; } else cout << (int)total + 1; return 0; }
19th Dec 2019, 9:25 AM
SHRABON
SHRABON - avatar
+ 1
It's weird that ceil was supposed to return integer value but the method worked. Thank's for the help...
19th Dec 2019, 9:36 AM
SHRABON
SHRABON - avatar