0

I am working on this loop to print out a meal for an order. I want to store multiple objects in an array so that they can be printed if more than one order wants to be entered. It runs the first loop without any problems however when it runs into the second loop the first two lines are entered and the user is unable to enter the entree it goes straight to the side. Any suggestions would be greatly appreciated.

#include "pch.h"
#include <iostream>
#include <string>

using namespace std;

class ComboMeal {
public:

    string entree;
    string side;
    string sideSize;
    string drink;
    string drinkSize;

    void printMeal() {
        std::cout << "Your combo meal is: " << endl;
        std::cout << "Entree: " << entree << endl;
        std::cout << "Side: " << sideSize << ' ' << side << endl;
        std::cout << "Drink: " << drinkSize << ' ' << drink<< endl;
    }



};

int main()
{
    ComboMeal comb[20];
    char userresponse = 'Y';

    if (userresponse != 'N')
        for (int i = 0; i <= 20; i++) {

            std::cout << " " << endl;
            std::cout << "Would you like a Hamburger, Cheeseburger, or chicken?" << endl;
            std::getline(cin, comb[i].entree);
            std::cout << "Would you like fries, tots, or a salad for your side?" << endl;
            std::getline(cin, comb[i].side);
            std::cout << "What size would you like your side?" << endl;
            std::getline(cin, comb[i].sideSize);
            std::cout << "What would you like to drink?" << endl;
            std::getline(cin, comb[i].drink);
            std::cout << "What size drink would you like?" << endl;
            std::getline(cin, comb[i].drinkSize);
            std::cout << "Would you like another meal?" << endl;
            std::cin >> userresponse;
            std::cout << " " << endl;
        }

    else
    {
        for (int j = 0; j <= 20; j++) {
            comb[j].printMeal();
        }
    }
}
  • You'll be much happier in the long run if you always uses braces for conditionals and loops. What's odd is you did for the else but not the if. *shrug* – Retired Ninja Mar 21 '19 at 03:22
  • Discuss the range of `i` in `for (int i = 0; i <= 20; i++)` with your [Rubber Duck](https://en.wikipedia.org/wiki/Rubber_duck_debugging). – user4581301 Mar 21 '19 at 03:24

0 Answers0