// Programmer: Dylan McDonald // Class & Section: CS 54, Section // Date: January 30, 2007 // Purpose: To gain weight at Clayton's Cafeteria #include using namespace std; int main() { /* delcare constants used in all parts */ const int DONUTCAL = 450, ICECAL = 350, PICAL = 500; const int DONUTFAT = 18, ICEFAT = 20, PIFAT = 15; const double DONUTPRICE = 1.5, ICEPRICE = 2.2, PIPRICE = 3.141592; const double GRAM2KILO = 0.001, GRAM2LB = 0.0022046; int choice; double weightGain = 0.0; /* part I - display menu */ /* part III added choice 4 */ cout << "Welcome to Clayton's Cafeteria!" << endl; cout << "1) Jelly Donuts $1.50" << endl; cout << "2) Ice Cream $2.20" << endl; cout << "3) Cherry Pie $3.141592" << endl; cout << "4) Exit" << endl << endl; /* part III - wrap previous parts in a loop */ do { /* part II - ask for what they want and validate it */ /* part I is the same without the do...while loop */ do { cout << "And what is your pleasure today? "; cin >> choice; } while (choice != 1 && choice != 2 && choice != 3 && choice != 4); /* part I - take the choice and print out the information */ /* ...for donuts */ if (choice == 1) { cout << "Your order costs $" << DONUTPRICE << ", has " << DONUTCAL << " calories, and " << DONUTFAT << " grams of fat." << endl; /* part III calculations */ weightGain = weightGain + 4.2 * DONUTCAL + 75 * DONUTFAT; } /* ...for ice cream */ else if (choice == 2) { cout << "Your order costs $" << ICEPRICE << ", has " << ICECAL << " calories, and " << ICEFAT << " grams of fat." << endl; /* part III calculations */ weightGain = weightGain + 4.2 * ICECAL + 75 * ICEFAT; } /* ...for pie */ else if (choice == 3) { cout << "Your order costs $" << PIPRICE << ", has " << PICAL << " calories, and " << PIFAT << " grams of fat." << endl; /* part III calculations */ weightGain = weightGain + 4.2 * PICAL + 75 * PIFAT; } /* ...do nothing for the exit option */ else if (choice == 4) { /* this semi colon is known as a "NULL statement" */ /* it's a statement that just does nothing */ ; } /* ...for items with DNE problems */ else { cout << "There exists no such item!" << endl; } } while (choice != 4); /* part III conversion from grams to kilograms */ /* (you could have also done grams to pounds) */ weightGain = weightGain * GRAM2KILO; cout << "You can expect to gain " << weightGain << " kg." << endl; return 0; }