0

I can't round accordingly

Am doing the code coach .. " Kalaidoscope" . When I run the program it says to round of upto 2 decimal places.. how can I round of it ..? Am inserting my code for reference.....please help https://code.sololearn.com/c64tJ8ZH3Il9/?ref=app

2nd Nov 2023, 5:46 PM
MOHAMMED SHAHUL
MOHAMMED SHAHUL - avatar
3 Respostas
+ 3
One way to do it, is using C formatting: printf("%.02f", price); Here some more ideas: https://www.geeksforgeeks.org/rounding-floating-point-number-two-decimal-places-c-c/
2nd Nov 2023, 5:56 PM
Lisa
Lisa - avatar
+ 3
For C++, this discussion might help: https://www.sololearn.com/Discuss/3197790/?ref=app
2nd Nov 2023, 11:31 PM
Brian
Brian - avatar
+ 3
cout << fixed << setprecision(2) << cost; //cpp way.. Include <iomanip> header file.. https://www.sololearn.com/Discuss/2486871/?ref=app
3rd Nov 2023, 3:51 AM
Jayakrishna 🇮🇳