C++ Menu. Unlimited loop in menu - c++

Hey can anyone see what wrong with my menu in the while loop it keeps printing out dixie if i press 1 in an unlimited loop. I have a while loop around the menu so that the menu is always there for the user to go back through choices.
here is my code:
#include <iostream>
using namespace std;
int main()
{
int choice;
bool menu = true;
cout <<"========Welcome to the database menu========\n";
cout << "Press 1 to insert a new record at a particular position\n"
"Press 2 to delete a record from a particular position\n"
"Press 3 to search the database and print results\n"
"Press 5 to find the average experience points of players at a particular level\n"
"Press 6 to find and remove all duplicate entries\n"
"Press 0 to quit\n\n\n\n\n\n\n\n\n";
cout << "Choice: ";
cin >> choice;
//*****************************************************************************
// Switch menu to display the menu.
//*****************************************************************************
while(menu)
{
switch (choice)
{
case 1:
cout << "dixie";
break;
case 2:
cout << "bexie";
break;
default:
cout<< "That is not a choice!!!\n";
}
}
getchar();
getchar();
}

There is no code that can change either menu or choice inside your while loop. So once it gets going, it will never stop.

It says while (menu) and that means it'll keep doing that until you set menu to false.
Also, I think you want to add the cin >> choice in the loop, or it'll just repeat the selection again and again.

I would suppose the while loop should include printing the menu options and having the user select an option like so:
while (menu)
{
cout <<"========Welcome to the database menu========\n";
cout << "Press 1 to insert a new record at a particular position\n"
"Press 2 to delete a record from a particular position\n"
"Press 3 to search the database and print results\n"
"Press 5 to find the average experience points of players at a particular level\n"
"Press 6 to find and remove all duplicate entries\n"
"Press 0 to quit\n\n\n\n\n\n\n\n\n";
cout<< "Choice: ";
cin>> choice;
switch (choice)
{
case 1:
cout << "dixie";
break;
case 2:
cout << "bexie";
break;
default:
cout<< "That is not a choice!!!\n";
}
}
Another possibility would be to start the while loop just before the cout << "Choice: " line.

menu variable is always true inside the loop. It's the same as while(true) at the moment.

Related

C++ 11db error when trying to quit the program in xcode. beginner level

I am in the begining steps to answer a Lottery HW problem, however, when I call the getLottoPicks function it throws off the program with an 11db error. So when the program first runs and you exit with 'q' or 'Q' it works, but if the user goes thru the program once and then tries to quit I get the 11db error. I tried sticking cin.ignore() in all sorts of places but that didn't help.
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cctype>
using namespace std;
void menu();
int getLottoPicks(int[], int);
int main()
{
char choice;
const int SIZE = 6;
int UserTicket[SIZE];
int WinningNums[SIZE];
string name;
do
{
menu();
cin >> choice;
cout << endl;
cin.ignore();
switch (choice)
{
case '1':
cout << "Please enter your name: ";
getline(cin, name);
getLottoPicks(UserTicket,SIZE);
for(int i = 0; i <= SIZE; i++)
{
cout << UserTicket[i];
cout << ", ";
}
cout << endl <<endl;
break;
case 'q':
case 'Q':
cout << "You have chosen to quit the program. Thank you for using!\n";
break;
default:
cout << "Invalide Selection.\n";
break;
}
}while (choice != 'q' && choice != 'Q');
return 0;
}
void menu()
{
cout << "1) Play Lotto\n";
cout << "q) Quit Program\n";
cout << "Please make a selection: \n";
}
int getLottoPicks(int nums[], int size)
{
cout << "Please enter your 7 lotto number picks between 1 and 40.\n";
for(int i = 0; i <= size; i++)
{
cout << "Please pick #" << i + 1 << ": ";
cin >> nums[i];
cout << endl;
}
return nums[0], nums[1], nums[2], nums[3], nums[4], nums[5], nums[6];
}
/* Here is a run thru of the program
1) Play Lotto
q) Quit Program
Please make a selection:
1
Please enter your name: asdf
Please enter your 7 lotto number picks between 1 and 40.
Please pick #1: 1
Please pick #2: 1
Please pick #3: 1
Please pick #4: 1
Please pick #5: 1
Please pick #6: 1
Please pick #7: 1
1, 1, 1, 1, 1, 1, 1,
1) Play Lotto
q) Quit Program
Please make a selection:
q
You have chosen to quit the program. Thank you for using!
(11db) <----- this is what I am getting in green color. and the program doesn't quit until i manually close it with Cmd .
*/
(lldb) is the command prompt for the LLDB debugger, not an error code. Your program has crashed, probably because you're loading 7 elements into an array of size 6.
The problem is in the function getLottoPicks.
First to point a design problem: you are somehow calling this function to get 7 inputs from the user but you are mistakenly returning 7 elements from the parameter nums (which in your case is causing the function to access the 7th element from an array that only contains 6 elements). Besides that you are already getting the values by storing the them in the nums parameter. Change the getLottoPicks return type to void and delete the return nums[0], nums[1], nums[2], nums[3], nums[4], nums[5], nums[6]; line.
Secondly you are using the condition to exit the for loops wrong. Arrays in C++ are accessed by indexes starting with 0. When you state the exit condition to a for loop to exit when the iterator becomes <= than the array size, you are actually making the code to cause a stack overflow problem when execute (it will write to the array variable beyond its boundaries). In the case of your code, change the <= operator to < in the for loop inside the getLottoPicks.

Stuck in loop within a function (C++)

I have written a program with several menus within it. I am now debugging the program and I wanted to include some input validation in the menu choices. However, for some reason, when it detects a wrong input it goes back to the beginning of the function with a goto statement (I know, bad practice :\) and It asks the user for a new input, but even if the input is right, it goes back to the case for non allowed inputs (default) no matter what. Does anyone have any idea of what's going on?
NOTE:
select_variable_check(vector<int> , int) is a function that checks if the value entered has been entered before if that is of any relevance, although I don't think it has anything to do with it.
void select(vector<int>&select_control) {
char select;
choices:
cin >> select;
int selectint = select;
bool check = select_variable_check(select_control, selectint);
switch (select) {
case ('1','2','3','4','5','6','7','8','9','10'):
if (check == false) {
string city = city_selection(selectint);
double xcoor = xcoor_selection(selectint);
double ycoor = ycoor_selection(selectint);
cout << "\n" << city << "\n";
select_control.push_back(selectint);
cout << "\n Enter next city: ";
cin >> select;
selectint = select;
}
else {
cout << "You have already selected that city, please select another one ";
cin >> select;
}
break;
case '99': {
cout << "TERMINATING" << endl;
Sleep(3000);
exit(0);
break;
}
case '100': {
cout << "input complete" << endl;
break;
}
default: {
cout << "not a valid value, please try again" << endl;
goto choices;
break;
}
}
The value of ('1','2','3','4','5','6','7','8','9','10') is '10', so that's the only value that will trigger that first case statement. The right way to write this is:
case '1':
case '2':
case '3':
...
Even with this change, though, '10' is a peculiar kind of character, and almost certainly not the right thing here.
Your code boils down to
start:
get_input
process_input
if good do something
else go to start
end:
Now when you enter bad input it goes back to start. Your input operation will fail again as the input stream is still in an error state so you do not get new input and since you have bad input you go back to start. To stop this loop you need to clear out the error flags on the stream and remove any input still in the buffer. That will make you default case look like
default: {
cout << "not a valid value, please try again" << endl;
cin.clear(); // removes error flags
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // flushes input buffer
goto choices;
break;
}
You will need to #include <limits> to use cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n')

loop not working?

After the call for Back to Main Menu, it returns to the mainMenu but when option or command is typed, the option is not accepted or the loop not working. Wonder where is the mistake? Is it extra call should be added or?
#include <iostream>
using namespace std;
char mainMenu(void);
int factorial(int n);
unsigned long long combination(long nK, long nR);
int main(){
char option;
int shape,function,i,j,k,t,n;
long nK, nR;
unsigned long long COM;
while((option=mainMenu())!='0')
{
switch(option)
{
case '1'://Program 1:
cout<< "*Drawing a shape\n"
<< "(1-Rectangle, 2-Triangle, 3-Inverted Triangle, 4-Letter 'H', 0-Back to Main Menu)\n";
do
{
cout<< "Choose shape >> ";
cin>> shape;
cout<< endl;
switch(shape)
{
case 1: break;
case 2: break;
case 3: break;
case 4: break;
case 0:
//Back to Main Menu
cout<< "Back to main menu\n"
<< endl;
return mainMenu(); //After here, it does back to Main Menu but command or option is not working
}
}while(shape!=0);
case '2': //Program 2
cout<< "*Choose function of calculator\n"
<< "(1-Factorial, 2-Combination, 0-Back to main menu)\n";
do
{
cout<< "Choose function >> ";
cin>> function;
cout<< endl;
switch(function)
{
case 1: break;
case 2: break;
case 0:
cout<< "Back to main menu\n"
<< endl;
return mainMenu();
}
}while(function!=0);
case '0':
cout<< "Program is terminating\n"
<< endl;
return 0;
default:
cout<< "Wrong input. Please choose one of the above options.\n"
<< endl;
return mainMenu();
}
}
}
char mainMenu(void){
char option;
cout<< "##############################\n"
<< "Main Menu\n"
<< "Enter your command!\n"
<< "##############################\n"
<< endl
<< "1. Program1\n"
<< "2. Program2\n"
<< "0. Exit\n"
<< endl
<< "Command >> ";
cin>> option;
cout<< endl;
return option;
}
I'm not sure what your question is, but your code is missing 2 important things. First, you need break statements at the end of each case block, otherwise the program flow will continue on to the next case statement.
Second, the inner menu doesn't ever escape the inner while(1) loop. This is a possible case for a goto use, although in practice it would better to refactor the code to split the top menu and inner menu into two functions, and use a return in the inner menu to return to the outer menu.
I'm not sure what your question is, but your code is missing 2 important things. First, you need break statements at the end of each case block, otherwise the program flow will continue on to the next case statement.
Second, the inner menu doesn't ever escape the inner while(1) loop. This is a possible case for a goto use, although in practice it would better to refactor the code to split the top menu and inner menu into two functions, and use a return in the inner menu to return to the outer menu.
As said, you're code is missing various things. It would be awesome if you distribute the entire code, and additionally the exact error message with line.
void value not ignored as it ought to be?...
...Is not that much of an explanation...
Also, are you sure you included iostream?
#include iostream
That said, you did not declare any of the variables used in the program.
You also missed a space in line 2 of your mainMenu() function.
Also, please tell us what you expected to happen.

My switch statement is not exiting the loop cleanly

I am currently testing out my driver program for my homework. What happens is that I have a menu printed with different options, and the program uses a switch statement based on the user's input to determine what to do. Everything works fine except for the "exit program" case, where it's supposed to leave the program and end it. Instead, it will print out the message "Quitting program" (like it's supposed to) and then follow up with doing one of the first 4 cases. It doesn't actually leave the switch statement. I don't know what could be wrong because I've used this method before and have not encountered this issue.
#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include "ListRecords.h"
#include "BookRecord.h"
using namespace std;
//Prints the menu for the user.
void printMenu(){
cout << "\n\n1) Insert a book record into the list\n";
cout << "2) Print information of a book with the given ISBN number\n";
cout << "3) Print the list of books, sorted by ISBN (lowest to highest)\n";
cout << "4) Print the list of books, sorted by title\n";
cout << "5) Quit the program\n";
cout << "Option: ";
}
//Menu block of the code. Takes in command choice and performs appropriate functions
void action(ListRecords books, int x){
cin.sync();
int option;
switch (x){
case 0: {
printMenu();
cin >> option;
action(books, option);
}
case 1: {
string title, author, pub;
long isbn;
cout << "\n\t**Inserting a new book into the record**";
cout << "\nTitle: ";
getline(cin, title);
cout << "Author: ";
getline(cin, author);
cout << "Publisher: ";
getline(cin, pub);
cout << "ISBN: ";
cin >> isbn;
BookRecord sample = BookRecord(title, author, pub, isbn);
books.insertBookInfo(sample);
cout << "\n\tNew book has been entered into the record\n\n";
printMenu();
cin >> option;
action(books, option);
}
case 2: {
long printISBN;
cout << "Printing book with ISBN number: ";
cin >> printISBN;
books.printBookInfo(printISBN);
cout << "\n\n";
printMenu();
cin >> option;
action(books, option);
}
case 3: {
cout << "\n\t**Printing all books in ISBN increasing order**\n";
//books.quickSortNum(0, books.seeFillSize());
books.rearrangeList(0);
books.printAll();
printMenu();
cin >> option;
action(books, option);
}
case 4: {
cout << "\n\t**Printing all books in alphabetical order**\n";
//books.quickSortNum(0, books.seeFillSize());
books.rearrangeList(1);
books.printAll();
printMenu();
cin >> option;
action(books, option);
}
case 5: {
cout << "\n\t**Quitting program. . .**\n";
return;
}
//For the purposes of debugging, I placed option 6 to print all books
case 6: {
books.printAll();
printMenu();
cin >> option;
action(books, option);
}
default: {
cout << "\n\t**ERROR: Invalid input. Try again**\nEnter option: ";
cin >> option;
action(books, option);
}
}
}
int main(void){
string fileName;
int option;
//Prompt for file name
cout << "Enter the name of the file: ";
cin >> fileName;
cout << "\nLoading the file and its contents. . .";
//Create a List Records object and clear stream
ListRecords books = ListRecords(fileName);
cin.sync();
cout << "\n\n";
//Start menu process. Beginning option is 0
action(books, 0);
//Once user quits, this will happen
cout << "\n Thanks for trying out this program!\n";
system("pause");
return 0;
}
The root cause of your problem is that your code uses recursion instead of iteration.
main makes a call to action, which goes into a switch, which then calls action again, which goes into the switch and calls action, until the Quit option is selected.
At this point the recursive call chain starts to unwind. Unfortunately, since your code lacks break statements, the switch is not exited immediately. Instead, the code falls through to the next case label, making you think that the return did not do its job at terminating the action. It did, but only the last action on the call stack is terminated. The remaining ones are still in progress, so they would continue as soon as the higher-level action finishes.
You can add break statements to your switch statement to mask the problem. However, the root cause would not go away: your program would remain poorly organized, and hard to read.
Consider rewriting the code using a while loop in the action function. Keep the switch, add breaks, and remove recursive calls to action from inside the switch. Instead, let the loop continue, so that the switch is re-entered and processed again, until the Quit option is selected.
First thing you do is call action(books, 0); to get to the menu.
switch (x){
case 0: {
printMenu();
cin >> option;
action(books, option);
}
There you call action(books, option); with the user supplied number.
You continue doing this for every option untill the user enters a 5 to end the program.
Because you don't have any break statements the code will go back to the 'calling case' and continue executing into the next case.
Be sure to end a case with a break to not continue executing the next case block (fall through).
Here is another questionn about why a break is needed.
In main() you call action(book, 0) so it enters action function. Then you prompt for choice and enter action() gain with that option. Then you enter 5 and quit that action, the return address of the nested action() call returns just after that call, at case 1: block and continues to execute it.
So what you need to do is put break statement at the end of each block.
When you don't use break after once case block, the code continues executing next case block.
So as the guy above said, you should consider placing break at the end of each block.
Also, you might want to consider not using recursion, but maybe iteration, and put prompt block outside the switch/case.

Navigating console menu

I'm totally new and I don't know how else to ask this or what to even search for.
The case is this: I want to navigate through a menu with several sub-menus. In this example I'll just use "options" and a "game" to illustrate what I mean. Say you have a menu with 3 options.
1 - Start
2 - Options
3 - Quit
Choosing options should take you to another menu. Which would then look something like
1 - Difficulty
2 - Sound
3 - Back
Depending on where you go from here, there will be more sub menus obviously.
I've tried nesting do-while loops and all kinds of things but I just don't have enough understanding to know what it is I'm doing wrong.
Here is what I have so far:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int choice;
do{
cout << "Main Menu\n";
cout << "Please make your selection\n";
cout << "1 - Start game\n";
cout << "2 - Options\n";
cout << "3 - Quit\n";
cout << "Selection: ";
cin >> choice;
switch(choice) {
case 1:
cout << "Pew pew!\n";
break;
case 2:
cout <<"????\n";
break;
case 3:
cout << "Goodbye!";
break;
default:
cout << "Main Menu\n";
cout << "Please make your selection\n";
cout << "1 - Start game\n";
cout << "2 - Options\n";
cout << "3 - Quit\n";
cout << "Selection: ";
cin >> choice;
}
} while(choice !=3);
system("PAUSE");
return EXIT_SUCCESS;
}
Which works like a regular menu. But I have no idea where to go from here. I consulted some books, but finding anything even remotely related to this was completely random. Any help or examples would be greatly appreciated.
What happened with nesting tons of loops just made all loops execute simultaneously every time. How do I keep this from happening? Making more choices? (choice1-2-3 etc ? or what?)
Ok guys. Thanks for all the help. This is what I ended up with in the end.
It runs as I want it to and by max_'s example and Mike B's commentary I think this works pretty well.
Thanks alot everyone =)
#include <iostream>
#include <cstdlib>
using namespace std;
void menu();
void mainMenu();
void optionsMenu();
void options();
int choice1 = 0;
int choice2 = 3;
int main(int argc, char** argv) {
menu();
return 0;
}
void menu(){
do {
choice2 = 0;
mainMenu();
switch(choice1) {
case 1:
cout << "Pew pew!\n";
break;
case 2:
options();
break;
case 3:
break;
}
} while(choice1 != 3);
}
void options(void) {
do {
optionsMenu();
switch(choice2){
case 1:
cout << "So difficult!\n";
break;
case 2:
cout << "Beep!\n";
break;
case 3:
break;
default:
break;
}
} while(choice2 != 3);
}
void mainMenu(void) {
cout << "Main Menu\n";
cout << "1 - Start game\n";
cout << "2 - Options\n";
cout << "3 - Quit\n";
cout << "Please choose: ";
cin >> choice1;
}
void optionsMenu(void) {
cout << "Options Menu\n";
cout << "1 - Difficulty\n";
cout << "2 - Sound";
cout << "3 - Back\n";
cout << "Please choose: ";
cin >> choice2;
}
How about this (dunno if it compiles though):
#include <cstdlib>
#include <iostream>
using namespace std;
int GetInput()
{
int choice;
cin >> choice;
return choice;
}
void DisplayMainMenu()
{
cout << "Main Menu\n";
cout << "Please make your selection\n";
cout << "1 - Start game\n";
cout << "2 - Options\n";
cout << "3 - Quit\n";
cout << "Selection: ";
}
void DisplayOptionsMenu()
{
cout << "Options Menu\n";
cout << "Please make your selection\n";
cout << "1 - Difficulty\n";
cout << "2 - Sound\n";
cout << "3 - Back\n";
cout << "Selection: ";
}
void Options()
{
int choice = 0;
do
{
system("cls");
DisplayOptionsMenu();
choice = GetInput();
switch(choice)
{
case 1:
cout << "difficulty stuff";
break;
case 2:
cout << "sound stuff";
break;
case 3:
break;
default:
break;
}
} while(choice!=3);
}
int main(int argc, char *argv[])
{
int choice = 0;
do
{
system("cls");
DisplayMainMenu();
choice = GetInput();
switch(choice) {
case 1:
cout << "Pew pew!\n";
break;
case 2:
Options();
break;
case 3:
cout << "Goodbye!";
break;
default:
break;
}
} while(choice!=3);
system("PAUSE");
return EXIT_SUCCESS;
}
I'd recommend that you change a few things here. Are you familiar with object-oriented design? If not, it's highly recommended that you read about that if you're looking to write code in C++ (Or just writing code in general, as it's a pretty major aspect of many programming languages)
Consider treating each of your menus and submenus as individual objects. Each time you enter the loop, use an object pointer to call a method that prints the current menu text.
Then, take the input from the user as normal, and change the menu object you're using now.
This is perhaps not the most ideal way to do a console menu, but it will give you a very strong grounding in how objected-oriented programming works.
I've attached an example :
#include <iostream>
#include <string>
class BaseMenu
{
public:
BaseMenu() { m_MenuText = "This shouldn't ever be shown!"; } // This is the constructor - we use it to set class-specific information. Here, each menu object has its own menu text.
virtual ~BaseMenu() { } // This is the virtual destructor. It must be made virtual, else you get memory leaks - it's not a quick explaination, I recommend you read up on it
virtual BaseMenu *getNextMenu(int iChoice, bool& iIsQuitOptionSelected) = 0; // This is a 'pure virtual method', as shown by the "= 0". It means it doesn't do anything. It's used to set up the framework
virtual void printText() // This is made virtual, but doesn't *have* to be redefined. In the current code I have written, it is not redefined as we store the menu text as a string in the object
{
std::cout << m_MenuText << std::endl;
}
protected:
std::string m_MenuText; // This string will be shared by all children (i.e. derived) classes
};
class FirstMenu : public BaseMenu // We're saying that this FirstMenu class is a type of BaseMenu
{
FirstMenu()
{
m_MenuText = "Main Menu\n" // What we are doing here is setting up the string to be displayed later
+ "Please make your selection\n" // What we are doing here is setting up the string to be displayed later
+ "1 - Start game\n" // What we are doing here is setting up the string to be displayed later
+ "2 - Options\n" // What we are doing here is setting up the string to be displayed later
+ "3 - Quit\n" // What we are doing here is setting up the string to be displayed later
+ "Selection: "; // What we are doing here is setting up the string to be displayed later
}
BaseMenu *getNextMenu(int choice, bool& iIsQuitOptionSelected) // This is us actually defining the pure virtual method above
{
BaseMenu *aNewMenu = 0; // We're setting up the pointer here, but makin sure it's null (0)
switch (choice) // Notice - I have only done "options". You would obviously need to do this for all of your menus
{
case 2:
{
aNewMenu = new SecondMenu; // We're creating our new menu object here, and will send it back to the main function below
}
case 3:
{
// Ah, they selected quit! Update the bool we got as input
iIsQuitOptionSelected = true;
}
default:
{
// Do nothing - we won't change the menu
}
}
return aNewMenu; // Sending it back to the main function
}
};
class SecondMenu : public BaseMenu
{
SecondMenu()
{
m_MenuText = "OptionsMenu\n"
+ "Please make your selection\n"
+ "1 - ????"
+ "2 - dafuq?";
}
BaseMenu *getNextMenu(int choice, bool& iIsQuitOptionSelected) // This is us actually defining the pure virtual method above
{
BaseMenu *aNewMenu = 0; // We're setting up the pointer here, but makin sure it's null (0)
switch (choice) // Notice - I have only done options. You would obviously need to do this for all of your menus
{
case 1:
{
aNewMenu = new FirstMenu; // We're creating our new menu object here, and will send it back to the main function below
}
break;
case 2:
{
aNewMenu = new FirstMenu; // We're creating our new menu object here, and will send it back to the main function below
}
break;
default:
{
// Do nothing - we won't change the menu
}
}
return aNewMenu; // Sending it back to the main function
}
};
int main (int argc, char **argv)
{
BaseMenu* aCurrentMenu = new FirstMenu; // We have a pointer to our menu. We're using a pointer so we can change the menu seamlessly.
bool isQuitOptionSelected = false;
while (!isQuitOptionSelected) // We're saying that, as long as the quit option wasn't selected, we keep running
{
aCurrentMenu.printText(); // This will call the method of whichever MenuObject we're using, and print the text we want to display
int choice = 0; // Always initialise variables, unless you're 100% sure you don't want to.
cin >> choice;
BaseMenu* aNewMenuPointer = aBaseMenu.getNextMenu(choice, isQuitOptionSelected); // This will return a new object, of the type of the new menu we want. Also checks if quit was selected
if (aNewMenuPointer) // This is why we set the pointer to 0 when we were creating the new menu - if it's 0, we didn't create a new menu, so we will stick with the old one
{
delete aCurrentMenu; // We're doing this to clean up the old menu, and not leak memory.
aCurrentMenu = aNewMenuPointer; // We're updating the 'current menu' with the new menu we just created
}
}
return true;
}
Note that this might be a bit complex for starting out. I strongly recommend you read the other answers people have posted. It should give you a few approaches on how to do it, and you can progress from the basic up to the more complex, examining each change.
Looking at what you are trying to do, I would change how you are ensuring the user still want's to play the game first. Look at using a while loop to check if a variable is true or false (people tend to use boolean variables(bool's) for this, an int set to 1 or 0 will do the same). That removes the need for the do-while. Reading up on control logic (if/else, while, for loops) and logical operators (&& - and, || - or, != - not equal to) is recommended. Control logic makes your code do different things, booleans are quick for checking yes/no scenarios and logical operators allow you to check multiple items in one if statement.
Some reading: Loops
Edit: Have more links for reading material, don't have the rep to post them.
Secondly, use another variable (int or whatever suits you) to track what screen you are on.
Based on this selection, display different options but still take input 1,2,3 to decide upon the next action.
In some terrible pseudo-code here is what I would lean towards:
main()
{
int choice
int screen = 1
bool running = true
while(running) {
//Screen 1, Main menu
if(screen == 1) {
cout << stuff
cout << stuff
cout << option 1
cout << option 2
cout << option 3
cout << selection:
cin >> choice
}
else if(screen == 2){
//options screen here
}
else {
//default/error message
}
//add some choice logic here
if(screen == 1 && choice == 3){
//being on screen one AND choice three is quit
running = false;
}
else if(screen == 1 && choice == 2){
//etc..
}
}
}
This is my first proper answer, all terrible criticism is well recieved.