I was wondering is there anyway for my code to repeat a certain process again without writing it over again.
Here is the part that I want to repeat.
1 2 3 4 5 6 7 8 9 10
cout << "Hello and welcome to Bobs's Pizza online ordering!" << endl;
cout << "Type 'food' to see food options and type 'drink' to see refreshments." << endl;
cin >> choice1;
if (choice1 == food) {
cout << endl;
cout << "Food Options" << endl;
cout << endl;
cout << "Pizza $15" << endl;
cout << "Salad $7" << endl;.
}
And here is that part I want it to go after.
1 2
if (finished == no);
cout << endl;
There must be an effient way of repeating it without copying and pasting it under it. Sorry if this is sloppy or if I haven't explained it well. Just started C++ last week :).
Thanks in advance.
If you need to look at the whole thing to understand it better, here it is.
Also what if the user enters Food or FOOD or FooD instead of "food"? You should lowercase or uppercase the string choice so that it will match "food" or "drink"
A simple way to post test loop the menu is a do while loop
do{
... statement
}while(true condition);
so in this case, you ask the user if he/she is finished Y for yes N for no
}while(choice == 'n' || choice == 'N');
this means while choice equals to n or N, then re-loop the menu
char * is a pointer-to-char or a C-Style string. std::string is better.
There are no differences, but the string object is better to use.
Also if you don't know this already, the keyword const makes a value unchangeble
There are no differences, but the string object is better to use.
Well there are a lot of differences. I think you meant they are both a string of characters.
A char array is just that and nothing else. If one wants to do anything with it, then one needs a function, or write your own code.
std::string is a C++ class, and that causes it have all kinds of advantages.
It has constructors, overloaded operators, the memory is dynamically allocated, knows it's size, STL algorithms work with it, it has it's own functions that do things, and more things if one reads the links to the documentation I posted earlier.