The question that I am attempting to work out is as follows :
"A government research lab has concluded that an artificial sweetener commonly used in diet soda pop
will cause death in lab mice. A friend of yours is desperate to lose weight but can't give up soda pop.
Your friend wants to know how much soda pop it's possible to drink without dying as a result. Write a
program to supply the answer. The input to the program is the amount of artificial sweetener needed to kill
a mouse, the weight of the mouse and the weight of the dieter. To ensure the safety of your friend, be sure
the program requests the weight at which the dieter will stop dieting, rather than the dieter's current weight.
Assume that diet soda contains 1/10th of 1% artificial sweetener. Use a variable declaration with the modifier
'const' to give a name to this fraction. You may want to express the percent as the double value of 0.001.
Your program should allow the calculation to be repeated as often as the user wishes."
I have completed the first draft of the code which is attached. My question is :
1) Is the logic of the program correct ? For example the cin values ;
SweetnerMouse = 0.080
WeightMouse(grams) = 50grams
WeightDieter(grams) = 65000grams
Yields the value '104000' for the variable (DietSodaPopCans); meaning that it takes 104000 cans
to kill the dieter at his/her given dieting weight. Does it sound sensible ? I feel that the two
equations written on the C++ code is logical. But I would need some checking on that please.
2) The question above requires that the program be repeated as many times as the user wishes. For this,
what type of looping mechanism could I use ? Would a while looping suffice or should I go for
The Source Code of the program is shown below :
//Soda Pop Death
//Date: 23 August 2011
using namespace std;
const double DIET_SODA_SWEETNER = 0.001;
cout << "This program calculates how many cans of soda it will take to kill you !\n";
cout << "Each can contains 0.001 (0.1%) of artificial sweetener\n" << endl;
cout << "Enter the amount of Artificial Sweetner needed to kill a mouse: \n";
cin >> SweetnerMouse;
cout << "Enter the weight of the mouse in grams: \n";
cin >> WeightMouse;
cout << "Enter the weight of the dieter in grams at which dieting activity will be stopped: \n";
cin >> WeightDieter;
SweetnerDieter = (SweetnerMouse/WeightMouse) * WeightDieter;
DietSodaPopCans = (SweetnerDieter/DIET_SODA_SWEETNER);
cout << "The amount of Diet Soda Pop Can's that would kill the dieter is: " << DietSodaPopCans;