Here's the problem 1 of Lab #2:
A metric ton is 35,273.92 ounces.
1. Write a program that will read the weight of a package of breakfast cereal in ounces and output the weight in metric tons as well as the number of boxes needed to yield one metric ton of cereal.
2. Your program should allow the user to repeat this calculation as often as the user wishes.
And here's my "precision error" on the digits after the dot:
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
The value weight_in_metric_tons is REALLY small if the value of package_of_breakfast_cereal_in_ounces is really small too. If this is the case, setting the precision to 2 will only fetch me the first two digits after the dot revealling 0.00 as the value for weight_in_metric_tons which is false. I should let the computer handle the precision in that calculation. I should test more numbers really close to zero though, to see if I get 0.000000000 (or something like that) as a result.
Note to self:
Practice more.
No comments:
Post a Comment