Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

an 2: Artificial Sweetener 1/31/17 Assigned Tuesday Program due of class Tuesday

ID: 3786441 • Letter: A

Question

an 2: Artificial Sweetener 1/31/17 Assigned Tuesday Program due of class Tuesday To format the output so the floating point values come out nicely insert the following three output formatting commands in your code right fter your variable declations (before you go into any loops they only need to be executed once-) If you are interested in exactly what these do at this point We may cover in class when we reach that point later in the senester cout,setf (ios fixed cout set f ios: showpoint out precision When your program asks for input, for values to use For amount to kill mouse ight of nouse weight of dieter 0.005 50.0 180 0.001 5.0 255 25.0 250 0.010 260 0.010 30.0 5.670 56.7 225 12.500 100.0 175 Assume the tirst 2 values are in grams Assume the 3rd is in pounds. Note that 1 pound 453.6 grans, if you need this conversion.) Note the test values above inelude numbe rts) less than 0 and 0's both of which are invalid and should prompt the user for correct again I'll say more in class ases for invalid data assume you get all three values and then verify. If you get them one at a time modify your testing accordingly Note that you need to do all these tests before s ubmission, AND include them all again when submitting Remember to use global constants where appropriate nt where needed, and indent reasonabl y for readability. Pick useful names Label your output and format it to read nicely. A government research lab has concluded that an artificial sweetener ly used in diet soda pop will cause death in laboratory mice A friend of yours is desperate to lose veight but cannot give up soda Pop. Your friend wants to know how mach diet soda Pop it is possible to drink without dying as a result program to supply the The input to the program is the amount of artificial sweetener kill a nouse. the weight of the mouse. and the weight of the dieter To insure the safety of your friend be sure the program request weight at which the dieter will stop dieting, rather than the dieter Assume that diet soda contains 1/10th of 11 artificial current weight Use a variable declaration with the nodifier to give a You may want to express the pereent as the Your program should allow the cal lculation to be repeated as often as the user wishes. The output should tell how many 16 oz (1 pound note that while the conversions betwee n fluid ounces and dry" ounces are actually more compl se these conversions given by proportion, is equivalent to that which will kill a human

Explanation / Answer

#include <iostream>

using namespace std;

int main()
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(4);

const double fraction = 0.001;

double kill_gram, mouse_weight, friend_weight_in_lb;

while(1)
{
cout << "For amount to kill mouse, weight of mouse, weight of dieter at stop : " << endl;
cin >> kill_gram >> mouse_weight >> friend_weight_in_lb;
if ((kill_gram <= 0) || (mouse_weight <= 0) || (friend_weight_in_lb <= 0))
{
cout << "Please enter value greater than 0." << endl;
}
else
{
double proportion_to_kill = kill_gram/mouse_weight;
double pound_to_kill = proportion_to_kill*friend_weight_in_lb;
double pound_soda = pound_to_kill/fraction;
cout << "Please stop at " << pound_soda << " cans else it will kill you ";

int choice = 0;
cout << "Want to try with other weight at which you should stop dieting? ";
cout << "Press 1 for yes. Press 2 for no.";
cin >> choice;
if (choice == 1)
continue;
break;
}
}
return 0;
}