Hello All,

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
do..while ?

Code:
```The  Source  Code  of  the  program  is  shown  below :

//Author: Andy8
//Soda Pop Death
//Date: 23 August 2011

#include <iostream>
using namespace std;

int main()
{

const double DIET_SODA_SWEETNER = 0.001;
int DietSodaPopCans;
double SweetnerMouse;
double WeightMouse;
double SweetnerDieter;
double WeightDieter;

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;

return 0;

}```
Thanks

2. Would a while looping suffice or should I go for
do..while ?
Doesn't matter.
You can fit any iterating logic into any form of loop.

Also, Why do you think you need loops for this?
Wouldn't a straight calculation of the value suffice ?

3. Hi ,

Thanks for your reply. You're right I wouldn't need a looping mechanism as the straight calculation seems to work just fine.
But the program should allow the calculation to be repeated as often as the user wishes.
So over here I think a looping mechanism must be employed. Which is why I was considering to use the 'while' looping.

4. Ok..in that case..
Put the main part within the loop
like:
Code:
```while(true)
{
/*Main Code*/
if(/*Condition for Quitting*/)
break;
cin.ignore();
}```

5. How To Ask Questions The Smart Way