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. | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
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 Bazar
Jayp Bazar - avatar
1 Antwort
+ 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