/*---
    WHAT IF: modified get_waffle_order, that "hard-codes" a certain
                 set of available waffle toppings,
             into
             get_waffle_order_2, expecting an ARRAY of available waffle
	         toppings and its size?

    (Both versions are included here, for easier comparison)

    by: Sharon Tuttle
    last modified: 2024-12-15
---*/

#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

/*===
    FROM Week 12 Lecture 1:
===*/

/*===
    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;
}

/*===
    NOW: making a version, get_waffle_order_2,
        that expects an array of available waffle toppings
	and its size...
===*/

/*===
    signature: get_waffle_order_2: string[] int -> string
    purpose: expects an array of available waffle toppings
        and its size,
        has the SIDE-EFFECT of asking the user whether
            they want each of THOSE choice of toppings,
        and returns their waffle order including the
            0-OR-MORE toppings they have requested
    tests:
        if you have:
        string monday_toppings[3] =
            {"bacon", "chocolate chips", "whipped cream"};

        then, when this is called,
            if the user answers n to EVERY topping when asked,

            get_waffle_order_2(monday_topping, 3) == "waffle"

        then, when this is called,
            if the user answers y to EVERY topping when asked,

            get_waffle_order_2(monday_topping, 3) ==
                "waffle + bacon + chocolate chips + whipped_cream"

        if you have:
        string weekend_toppings[4] =
            {"cherries", "bananas",
            "strawberries", "whipped cream"};

        then, when this is called,
            if the user answers y to JUST bananas and whipped cream,

            get_waffle_order_2(weekend_toppings, 4) ==
                "waffle + bananas + whipped cream"

===*/

string get_waffle_order_2(string toppings[], int size)
{
    // start of a waffle order!

    string waffle_order = "waffle";

    // holds the latest user-topping answer

    char latest_answer;

    // ask whether the user wants each available
    //     waffle topping, and adjust the waffle order
    //     accordingly

    cout << "on your waffle, do you want: " << endl;

    for (int i = 0; i < size; i++)
    {
        cout << "... "
	     << toppings[i]
	     << "? (y for yes, anything else for no): "
             << endl;
        cin >> latest_answer;

        if (latest_answer == 'y')
        {
            waffle_order = waffle_order + " + " + toppings[i];
        }
    }

    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;

    cout << endl;
    cout << "*** Testing: get_waffle_order_2 ***" << endl;

    cout << endl;
    cout << "Please answer n for EVERY question for this test!"
         << endl;

    string monday_toppings[3] =
            {"bacon", "chocolate chips", "whipped cream"};

    test_order_1 = get_waffle_order_2(monday_toppings, 3);

    cout << "You should NOW see an order of JUST waffles: "
         << endl
         << test_order_1
         << endl;

    cout << endl;
    cout << "Please answer y for EVERY question for this test!"
         << endl;

    test_order_2 = get_waffle_order_2(monday_toppings, 3);

    cout << "You should NOW see an order of waffle with  "
         << endl
         << "    bacon, chocolate chips, and whipped cream: "
         << endl
         << test_order_2
         << endl;

    cout << endl;
    cout << "Please answer y for JUST bananas and whipped cream for this test!"
         << endl;

    string weekend_toppings[4] =
            {"cherries", "bananas",
            "strawberries", "whipped cream"};

    test_order_3 = get_waffle_order_2(weekend_toppings, 4);

    cout << "You should NOW see an order of waffle with  "
         << endl
         << "    just bananas and whipped cream: "
         << endl
         << test_order_3
         << endl;

    // now, just playing around with an interactive "front end"
    //     for get_waffle_order_2:

    cout << endl << "NOW -- just to try it out interactively: "
         << endl << "==========================================" << endl;

    string user_order;

    user_order = get_waffle_order_2(weekend_toppings, 4);

    cout << endl << "Your order is: "
         << user_order << endl
         << "Enjoy!" << endl << endl;

    return EXIT_SUCCESS;
}