0
I got the first tests right. But the 3 hidden tests are wrong. Can anyone find the error in the code?
You are getting ready to paint a piece of art. The canvas and brushes that you want to use will cost 40.00. Each color of paint that you buy is an additional 5.00. Determine how much money you will need based on the number of colors that you want to buy if tax at this store is 10%. #include <iostream> using namespace std; int main() { int canvas = 40; int number; int paint ; int sum ; float tax ; float total ; cin >> number ; paint = number * 5 ; sum = paint + canvas ; tax = sum / 10; total = sum + tax ; cout << total ; return 0; }
3 Antworten
+ 1
Use ceil math function for it . Don't use sum . As each colour is additional so use this formula 5*number +40.
0
Hi! most likely all your values should be float and only the final result should be rounded to the nearest integer. use the rounding function
0
The problem is in the line 15: `tax = sum / 10`.
How it executes: sum and 10 are both int, so it returns an integer, for example, 4 when the sum is 45. But in the program it should be float/double/long double.
How to fix this:
1. Replace `int sum;` with `float sum;` (or `double sum;`, or `long double sum;`, depending on how precisely you want your program to be (note that tax and total are still float, so it will give no effect unless you change their type as well)).
2. Replace `sum` in `tax = sum / 10;` with `(float) sum`, so that a float value will be used in the division and float value will be returned.