Paint Costs | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Paint Costs

I was doing the community challenge, Paint costs, and ran into some trouble. My code passed two out the four test cases, I want to k own why it did not pass the other two test cases. https://code.sololearn.com/c50yiqx9nH51/?ref=app

6th Feb 2023, 2:54 PM
Blessing Malema
Blessing Malema - avatar
8 Answers
+ 3
the kid next door The tax defined as int and being rounded gives incorrect values, which fails those test cases. Tax should be float and not rounded. The final total cost needs to be rounded UP to an integer. Try using the `ceil` function to wrap the expression: ceil(((colorPick * colorCost) + canvasAndBrushes ) + storeTax);
6th Feb 2023, 3:52 PM
Mozzy
Mozzy - avatar
+ 1
Mmmh..It is not possible to determine why your code is not passing all test cases without knowing the specific inputs and expected outputs for those test cases anyway one issue with the code is that the storeTax calculation is rounded after dividing by 10, but it should be rounded before dividing by 10. This could result in incorrect store tax amounts and therefore incorrect total costs.
6th Feb 2023, 3:51 PM
ArsenicolupinIII
+ 1
Indeed I agree with Mozzy it is true that the tax is calculated as an integer and rounded which gives incorrect values ​​and fails some test cases, the fee should be a float and not rounded, the final total cost must be rounded up to a whole, try using the "ceil" function to wrap the calculation expression.
6th Feb 2023, 3:56 PM
ArsenicolupinIII
+ 1
I always had a problem with these challenges involving taxes as I live in EU. Anyway, I sligthly changed your solution and it passed all tests. #include <iostream> #include<cmath> using namespace std; int main() { int colorPick; cin >> colorPick; float canvasAndBrushes=40.00; float canvasAndBrushesTotal=canvasAndBrushes+canvasAndBrushes*0.1; float colorCost=5.00; float colorTotal=colorPick*(colorCost+colorCost*0.1); int totalCost=round(colorTotal+canvasAndBrushesTotal); cout << totalCost; return 0; }
6th Feb 2023, 4:08 PM
Mateusz Kempa
Mateusz Kempa - avatar
+ 1
Yes, Arsenicolupinlll is right in this case. For example, this is my solution in python :D from math import ceil paints = int(input()) print(ceil(44+(paints*5.5))) Another example would be code challange "Digits of Pi". You could simply paste Pi up to 1000 decimal points and output required digit. Whether is good or bad practice - it's not the topic of this discussion. In this case, I think it's neccessary because of requirements of solving this particular challange.
6th Feb 2023, 4:19 PM
Mateusz Kempa
Mateusz Kempa - avatar
+ 1
thanks Mateusz and I agree using the "ceil" function to round to the next integer is a correct solution to the problem, I'd like to add that it's very helpful to see the solution in another programming language, like Python, because it helps us better understand the problem and learn new techniques.
6th Feb 2023, 4:26 PM
ArsenicolupinIII
+ 1
we can make mistakes and learn at the same time, we are here to learn knowledge and exchange information
6th Feb 2023, 4:36 PM
ArsenicolupinIII
0
Mirielle you can determine the input of a test case by referring to the problem statement or by looking at sample inputs provided in the question. Sometimes, if you are given access to the code, you can also look at the test cases and the expected output to get an idea of the inputs. Additionally, you can also try to make educated guesses based on the constraints mentioned in the problem statement and test your code with those inputs.
6th Feb 2023, 4:15 PM
ArsenicolupinIII