0

I am working on a program that will establish a class of a Combo meal with specific parameters for the objects. I am storing these in a vector. The vector appears to be running appropriately but when I use the print function it is not printing anything. I need help getting the print function to operate appropriately.

I have tried using the .at() instead of getEntree() but still am not receiving any output. I have read several pieces on here about printing from a vector and still am unable to get any output from my program.

#include <iostream>
#include <string>
#include <vector>
#include "Combo.h"


void fillOrder(vector<Combo>);
void printOrder(vector<Combo>);

int main()
{
    vector<Combo> myOrder;

    fillOrder(myOrder);
    printOrder(myOrder);
}

vector<Combo> newMyOrder;
void fillOrder(vector<Combo> newMyOrder) {
    string entree;
    string side;
    string sideSize;
    string drink;
    string drinkSize;

    cout << "How many meals would you like to order? ";
    int orderSize;
    cin >> orderSize;

    for (int i=0; i < orderSize; i++) {
        cout << "Would you like a Hamburger, Cheeseburger, or chicken?" << endl;
        cin >> entree;
        cout << "Would you like fries, tots, or a salad for your side?" << endl;
        cin >> side;
        cout << "What size would you like your side?" << endl;
        cin >> sideSize;
        cout << "What would you like to drink?" << endl;
        cin >> drink;
        cout << "What size drink would you like?" << endl;
        cin >> drinkSize;

        Combo newMeal(entree, side, sideSize, drink, drinkSize);
        newMyOrder.push_back(newMeal);

    }
}
    void printOrder(vector<Combo>newMyCombo) {
        unsigned int size = newMyCombo.size();

        for (unsigned int i = 0; i < size; i++) {
            cout << "Your Entree is : " << newMyCombo[i].getEntree()<<endl;
            cout << "Your side is : " << newMyCombo[i].getSide()<<endl;
        }
    }

I am wanting this program to take the order then print a summary of the order, but I am getting no output at all.

Jeremy Sawyer
  • 83
  • 1
  • 6

1 Answers1

2

Pass by reference

Try:

void fillOrder(vector<Combo>&);

void fillOrder(vector<Combo>& newMyOrder)

If you'd want the print function to not work on a copy (as it is just printing the orders) use void printOrder(const vector<Combo>&); instead. The const qualifier will give you a compile guarantee that a function that should not modify the container does not really do that. Passing this by reference to print will ensure that you don't waste time and space in copying the whole thing.

rranjik
  • 690
  • 9
  • 21