Please help me with the 'logic' of this program

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 looping ?

The completed C++ Source code is as 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;


}

Thank You,
closed account (z6X8T05o)
I guess this could help you!
Add me on Skype if you ever see this message ( stevan-petrov )



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <cstdlib>
#include <iostream>

//Author: Andy8
//Soda Pop Death
//Date: 23 August 2011
//Edited by MrEARTHSHAcKER ( skype stevan-petrov )

#include <iostream>
using namespace std;

int main()
{

here:
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; 


system("PAUSE");
system("CLS");
goto here;
}

Please don't double post. http://cplusplus.com/forum/general/49158/

This is clearly a beginners question but I suggest you look at the other answer which doesn't use bad ideas like system calls and (ugh) a goto!
Topic archived. No new replies allowed.