1

Here is my code.

string HCoffees;
        cout
                << "\nPlease choose one of these hot coffees. Type your selection here: "
                << flush;
        while (cin.get() != '\n')
            ;
        getline(cin, HCoffees);

        cout << "\nNow at the " << HCoffees << " section.\n" << endl;

        //If the selection is a Caffe Americano...

        if (HCoffees == "Caffe Americano" || HCoffees == "caffe americano"
                || HCoffees == "Caffe americano" || HCoffees == "caffe Americano") {
            cout << "\nWhat size Caffè Americano would you like? " << flush;
            string size;
            cin >> size;
            if (size == "Tall" || size == "tall") {
                cout << "That will be 2.25.\n\nHow many Caffè Americanos (Tall size) would you like to get?" << flush;
            }
            else if (size == "Grande" || size == "grande") {
                cout << "That will be 2.65.\n\nHow many Caffè Americanos(Grande size) would you like to get?" << flush;
            }
            else if (size == "Verti" || size == "verti") {
                cout << "That will be 2.95.\n\nHow many Caffè Americanos(Verti size) would you like to get?" << flush;
            } else {
                cout << "Size not avaliable. Chose a different size: " << flush;

            }
        }

    }

Even though Caffe Americano is typed into the console (the user inputed this selection), it does not print out "What size Caffe Americano would you like?" (this is what I had programmed it to do on line 13 if Caffe Americano was typed). I had thought there had been something wrong with the way I got the input of the user, but I was incorrect, because I had already used this same input code* earlier on in my program, and it worked. Please try to solve this. Thanks!

*input code that is also shown above:

string HCoffees;
        cout
                << "\nPlease choose one of these hot coffees. Type your selection here: "
                << flush;
        while (cin.get() != '\n')
            ;
        getline(cin, HCoffees);

        cout << "\nNow at the " << HCoffees << " section.\n" << endl;
ssingh
  • 31
  • 5

0 Answers0