Order Menu

How do I display everything that user ordered, at the end??

#include <iostream>
using namespace std;


void menuOptions(string menu[]) {
for (int i=0; i <10; i++)
cout << menu[i] << endl;

}

int main () {
int menuNum[10] = {0,0,0,0,0,0,0,0,0,0};

char userIn = '0';
string menu[10] = {"Enchiladas", "Hamburgers", "Burritos", "Tacos" "Salad", "Cheesecake", "Muffins", "Pancakes", "Hashbrowns", "Pizza"};
char userChoice = 'x';
int i = 0;
char done;
done = 'd'; 'D';

cout << "The items you can choose from: " << endl;
menuOptions(menu);



while (userChoice != 'D' && userChoice != 'd') {


cout << "Choose type d or D to indicate that you are done choosing an item." << endl;
cout << "To select an item off of the menu select a number: " << endl;
cin >> userChoice;


if (userChoice <= 9 + 48) {

cout << "you chose: " << menu[userChoice - 48] << endl;
}

else if (userChoice > 10 + 48 && userChoice != 'd' && userChoice != 'D') {
cout << "I'm sorry, but you entered an invalid entry. Please enter a value found on the menu" << endl;
}


if ( userChoice == 'd' || userChoice == 'D') {

/* for (i = 0, i < 10; i++;) {


cout << " selected " << menuNum[i] << " time." << endl;*/

cout << "Goodbye." << endl;


}


}

}
Last edited on
Generally, I'd want to store the quantity and identity of items ordered so that information can be used later.
How do I do that though?
#include <iostream>
using namespace std;


void menuOptions(string menu[]) {
for (int i=0; i <10; i++)
cout << menu[i] << endl;

}

int main () {



int menuNum[10] = {0,0,0,0,0,0,0,0,0,0};


char userIn = '0';
string menu[10] = {"Enchiladas", "Hamburgers", "Burritos", "Tacos" "Salad", "Cheesecake", "Muffins", "Pancakes", "Hashbrowns", "Pizza"};
char userChoice = 'x';
int i = 0;
char done;
done = 'd'; 'D';

cout << "The items you can choose from: " << endl;
menuOptions(menu);



while (userChoice != 'D' && userChoice != 'd') {


cout << "Choose type d or D to indicate that you are done choosing an item." << endl;
cout << "To select an item off of the menu select a number: " << endl;
cin >> userChoice;


if (userChoice <= 9 + 48) {

cout << "you chose: " << menu[userChoice - 48] << endl;
}

else if (userChoice > 10 + 48 && userChoice != 'd' && userChoice != 'D') {
cout << "I'm sorry, but you entered an invalid entry. Please enter a value found on the menu" << endl;
}


if ( userChoice == 'd' || userChoice == 'D') {
menuNum[userChoice - 48] = 1;

cout << "Goodbye." << endl;


}


}
cout << "you chose: " << menuNum[userChoice + 48] << endl;

}
Try using an std::vector of orders and store an order each time a user makes one like the following:
1
2
3
4
5
6
7
8
9

std::vector<std::string> previousOrders

if (userChoice <= 9 + 48) {

    cout << "you chose: " << menu[userChoice - 48] << endl;

    previousOrders.push_back(menu[userChoice]);
}


When you want to print you can do the following

1
2
3
for(int i - 0; i < previousOrders.size(); i++){
     std::cout << previousOrders[i] << std::endl;
}

Thank you so much. It worked but this is the output:

Running /home/ubuntu/workspace/lab15/lab15.cpp
The items you can choose from:
Enchiladas
Hamburgers
Burritos
TacosSalad
Cheesecake
Muffins
Pancakes
Hashbrowns
Pizza

Choose type d or D to indicate that you are done choosing an item.
To select an item off of the menu select a number:
5
you chose: Muffins
SHELL=/bin/bashTERM=screenIRBRC=/usr/local/rvm/rubies/ruby-2.3.0/.irbrcSSH_CLIENT=::ffff:10.240.1.7 54444 22ISOUTPUTPANE=1NVM_PATH=/home/ubuntu/.nvm/versions/node/v4.4.5/lib/nodeC9_PORT=8080METEOR_IP=0.0.0.0MY_RUBY_HOME=/usr/local/rvm/rubies/ruby-2.3.0PHPRC=/home/ubuntu/workspaceLC_ALL=C.UTF-8NVM_DIR=/home/ubuntu/.nvmUSER=ubuntuLD_LIBRARY_PATH=~/.c9/local/lib_system_type=Linuxrvm_path=/usr/local/rvmC9_UID=1412023TMUX=/tmp/tmux-1000/cloud92.2,50336,0C9_IP=0.0.0.0rvm_prefix=/usr/localAPACHE_LOG_DIR=/home/ubuntu/lib/apache2/logPATH=/home/ubuntu/.nvm/versions/node/v4.4.5/bin:/usr/local/rvm/gems/ruby-2.3.0/bin:/usr/local/rvm/gems/ruby-2.3.0@global/bin:/usr/local/rvm/rubies/ruby-2.3.0/bin:/mnt/shared/bin:/home/ubuntu/workspace/node_modules/.bin:/home/ubuntu/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/mnt/shared/sbin:/opt/gitl:/opt/go/bin:/mnt/shared/c9/app.nw/bin:/usr/local/rvm/binC9_USER=tkinsey95HGUSER=Tiriah KinseyNVM_NODEJS_ORG_MIRROR=https://nodejs.org/distPWD=/ho
Those are just environment variables for your system. No need to worry about them.
Happy coding :)
Topic archived. No new replies allowed.