You are viewing a single comment's thread. Return to all comments →
Using the floor method will provide more consistent results:
mealCost = mealCost + tip + tax; //(assuming tip and tax were calculated correctly)
cout << floor(mealCost + 0.5) << endl;
If adding 0.5 brings it to an even number, floor returns the same number, otherwise it always rounds down, which is the result we are after.
Seems like cookies are disabled on this browser, please enable them to open this website
Day 2: Operators
You are viewing a single comment's thread. Return to all comments →
Using the floor method will provide more consistent results:
mealCost = mealCost + tip + tax; //(assuming tip and tax were calculated correctly)
cout << floor(mealCost + 0.5) << endl;
If adding 0.5 brings it to an even number, floor returns the same number, otherwise it always rounds down, which is the result we are after.