0

Can anyone help me with this code??? It's a problem from code coach and I got 2/5 and I can't find why the other 3 were wrong.

#include <iostream> using namespace std; int main() { const int bought_item = 40; const int paint_price = 5; const float tax = 0.1; int no_of_paints, total, vat; cin>>no_of_paints; no_of_paints *= paint_price; total = bought_item + no_of_paints; vat = total * tax; total += vat; cout<<total; return 0; }

10th Aug 2020, 2:59 AM
Jayp
Jayp - avatar
1 Respuesta
+ 1
But because the tax is float, so total * vat will return float which will then lose precision. Change them to doubles. Also, you have to print the number rounded to the nearest whole number. Your total and vat both are ints.
10th Aug 2020, 3:39 AM
XXX
XXX - avatar