+ 1

Why am I getting answer as .445 and the expected answer is .45? (Kaleidoscope problem)

Should i round off the answer? Or am i making any mistake in the code? #include <iostream> using namespace std; int main() { float num; cin >> num; if (num >1){ float cost = num * 5.00; float disc = cost * 0.1; float new_cost = cost - disc; float tax = 0.07 * new_cost ; float aft_tax = new_cost + tax; cout << aft_tax; } if (num==1) { float tax1 = 0.07 * 5.00; float cost1 = tax1 + 5.00; cout << cost1 ; } return 0; }

14th Feb 2023, 9:14 AM
Kruti
Kruti - avatar
5 Answers
+ 4
I solved it in python and I had to round it.
14th Feb 2023, 9:48 AM
Paul
Paul - avatar
+ 2
Round it upto 2 decimal digits.. double type gives you more accurate values..
14th Feb 2023, 10:35 AM
Jayakrishna 🇼🇳
0
Hello
14th Feb 2023, 11:37 AM
Jahongir Islomov
Jahongir Islomov - avatar
0
Try using double instead of float
15th Feb 2023, 8:46 PM
Alex Wairegi
Alex Wairegi - avatar
0
Round (ans, 2) should solve that issue
15th Feb 2023, 9:48 PM
Josh Allen