Hello there.
I want to do something very simple but probably the solution is very tricky since I am still very new to programming, I have a main menu void function which I call in Main to be printed out, then I select from that main menu the option I want and it leads me to a sub-menu, from that sub-menu which is already located in others function I want to go back to the main menu located in main by pressing Escape key at any moment while working on that function, any simple way to do so?
#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstdlib>
usingnamespace std;
void printMainMenu()
{
code here
}
double funtion01()
{
//sub menu
code here
}
double funtion02()
{
//sub menu
code here
}
double funtion03()
{
//sub menu
code here
}
int main()
{
int option;
printMainMenu();
cout << " Choose an option: ";
cin >> option;
// code here
// if press 1 go to function01() if 2 go to function02() and so on
return 0;
}
int main()
{
int option;
bool running = true;
while(running)
{
printMainMenu();
cout << " Choose an option: ";
cin >> option;
switch(option)
{
// code here
// if press 1 go to function01() if 2 go to function02() and so on
// when exit chosen set running to false
}
}
return 0;
}
Escape is a key with the numerical value of 27 - if I remember correctly. So when a key is pressed you need to check if it is the Escape key and then you exit the function.