/*--- CS 111 - Week 12 Lecture 1 - 2024-11-12 by: Sharon Tuttle last modified: 2024-11-12 ---*/ #include <cstdlib> #include <iostream> #include <string> #include <cmath> using namespace std; /*=== signature: get_waffle_order: void -> string purpose: expects nothing, has the SIDE-EFFECT of asking the user whether they want each of a choice of toppings, and returns their waffle order including the 0-OR-MORE toppings they have requested tests: when this is called, if the user answers n to EVERY topping when asked, get_waffle_order() == "waffle" when this is called, if the user answers y to EVERY topping when asked, get_waffle_order() == "waffle + chocolate chips + maple syrup + fruit + honey + whipped cream + peanut butter + bananas + butter" when this is called, if the user answers y to JUST fruit and honey, get_waffle_order() == "waffle + fruit + honey" ===*/ string get_waffle_order() { // start of a waffle order! string waffle_order = "waffle"; // holds the latest user-topping answer char latest_answer; cout << "do you want chocolate chips? (y for yes, anything else for no): " << endl; cin >> latest_answer; if (latest_answer == 'y') { waffle_order = waffle_order + " + chocolate chips"; } cout << "... maple syrup? (y for yes, anything else for no): " << endl; cin >> latest_answer; if (latest_answer == 'y') { waffle_order = waffle_order + " + maple syrup"; } cout << "... fruit? (y for yes, anything else for no): " << endl; cin >> latest_answer; if (latest_answer == 'y') { waffle_order = waffle_order + " + fruit"; } cout << "... honey? (y for yes, anything else for no): " << endl; cin >> latest_answer; if (latest_answer == 'y') { waffle_order = waffle_order + " + honey"; } cout << "... whipped cream? (y for yes, anything else for no): " << endl; cin >> latest_answer; if (latest_answer == 'y') { waffle_order = waffle_order + " + whipped cream"; } cout << "... peanut butter? (y for yes, anything else for no): " << endl; cin >> latest_answer; if (latest_answer == 'y') { waffle_order = waffle_order + " + peanut butter"; } cout << "... bananas? (y for yes, anything else for no): " << endl; cin >> latest_answer; if (latest_answer == 'y') { waffle_order = waffle_order + " + bananas"; } cout << "... butter? (y for yes, anything else for no): " << endl; cin >> latest_answer; if (latest_answer == 'y') { waffle_order = waffle_order + " + butter"; } return waffle_order; } /*--- test the functions above ---*/ int main() { cout << boolalpha; cout << endl; cout << "*** Testing: get_waffle_order ***" << endl; cout << endl; cout << "TEST 1: Please answer n for EVERY question for this test!" << endl << "=========================================================" << endl; string test_order_1 = get_waffle_order(); cout << endl << "You should NOW see an order of JUST a waffle: " << endl << "=========================================================" << endl << test_order_1 << endl; cout << endl; cout << "TEST 2: Please answer y for EVERY question for this test!" << endl << "=========================================================" << endl; string test_order_2 = get_waffle_order(); cout << endl << "You should NOW see an order of waffle with EVERYTHING: " << endl << " chocolate chips, maple syrup, fruit, honey, whipped cream, " << endl << " peanut butter, bananas, and butter: " << endl << "=========================================================" << endl << test_order_2 << endl; cout << endl; cout << "TEST 3: Please answer y for JUST fruit and honey for this test!" << endl << "=========================================================" << endl; string test_order_3 = get_waffle_order(); cout << endl << "You should NOW see an order of waffle with JUST fruit and honey: " << endl << "=========================================================" << endl << test_order_3 << endl; // now, just playing around with an interactive "front end" for get_waffle_order: cout << endl << "NOW -- just to try it out interactively: " << endl << "==========================================" << endl; string user_order; user_order = get_waffle_order(); cout << endl << "Your order is: " << user_order << endl << "Enjoy!" << endl << endl; return EXIT_SUCCESS; }