hii i need help.. when im in stack or queue menu when i choose exit i need to go back to my main menu without using a goto statements and in a new screen.
i have a missing code in stack case 7 and queue case 6 in order for it to return in the main menu
int main (){
int m_menu,s_menu,q_menu,userInput,searchThis;
Stack classStack;
Queue classQueue;
{
system("cls");
cout<<"\n*************************************";
cout<<"\n\t MAIN MENU\n";
cout<<"*************************************";
cout<<"\n\n\t (1) STACK \n\t (2) QUEUE \n\t (3) QUIT \n\n";
cout<<"Enter your choice:\t";
cin>>m_menu;
}
if (m_menu==1){
system("cls");
while (1) {
cout<<"\n*************************************"<<endl;
cout<<"\t STACK MENU\n";
cout<<"*************************************"<<endl;
cout<<"\n\t (1) Add \n\t (2) Delete \n\t (3) Sort \n\t (4) Top \n\t (5) Display \n\t (6) Search \n\t (7) Exit \n\n";
cout<<"Enter your choice: \t";
cin>>s_menu;
cout<<"-------------------------------------"<<endl<<endl;
switch (s_menu) {
case 1:
cout<<"\n\n\t What do you want to put in your stack? \t";
cin>>userInput;
classStack.addStack(userInput);
break;
case 2: cout<<"\n\n\t Your deleted value is: \t"<<classStack.deleteTop()<<endl; break;
case 3: classStack.sortingStack(); break;
case 4: classStack.topStack(); break;
case 5: classStack.displayStack(); break;
case 6:
cout<<"\n\n\t What are you searching for in your stack?\t";
cin>>searchThis;
classStack.searchingStack(searchThis);
break;
case 7:
default: cout<<"\n\n\t INVALID INPUT NUMBER!"<<endl;
} } }
elseif(m_menu==2){
system("cls");
while (1) {
cout<<"\n*************************************";
cout<<"\n\t QUEUE MENU\n";
cout<<"*************************************";
cout<<"\n\n\t (1) Add \n\t (2) Delete \n\t (3) Sort \n\t (4) Display \n\t (5) Search \n\t (6) Exit \n\n";
cout<<"Enter your choice: \t";
cin>>q_menu;
cout<<"-------------------------------------";
switch (q_menu) {
case 1 :
cout<<"\n\n\t ADD\n\n\t What do you want to put in your queue? \t";
cin>>userInput;
classQueue.addQueue(userInput);
break;
case 2:
cout<<"\n\n\t DELETE \n\t\t\t\t";
classQueue.deleteFront();
break;
case 3:
cout<<"\n\n\t SORT \n";
classQueue.sortingQueue();
break;
case 4:
cout<<"\n\n\t DISPLAY \n";
classQueue.displayQueue();
break;
case 5:
cout<<"\n\n\t SEARCH \n\n\t What are you searching for in your queue?\t";
cin>>searchThis;
classQueue.searchingQueue(searchThis);
break;
case 6:
default: cout<<"\n\n\tInvalid input number!\n";
} } }
elseif (s_menu=3){
return 0;
}
else {
cout<<"\n\n\tInvalid input number!\n"; }
}
#include <iostream>
int showMainMenu() {
int m_menu;
cout<<"\n*************************************";
cout<<"\n\t MAIN MENU\n";
cout<<"*************************************";
cout<<"\n\n\t (1) STACK \n\t (2) QUEUE \n\t (3) QUIT \n\n";
cout<<"Enter your choice:\t";
cin>>m_menu;
return m_menu;
}
int showStackMenu() {
int s_menu;
cout<<"\n*************************************"<<endl;
cout<<"\t STACK MENU\n";
cout<<"*************************************"<<endl;
cout<<"\n\t (1) Add \n\t (2) Delete \n\t (3) Sort \n\t (4) Top \n\t (5) Display \n\t (6) Search \n\t (7) Exit \n\n";
cout<<"Enter your choice: \t";
cin>>s_menu;
return s_menu;
}
void doStack() {
bool done = false;
while ( !done ) {
int s_menu = showStackMenu();
switch (s_menu) {
case 1:
cout<<"\n\n\t What do you want to put in your stack? \t";
cin>>userInput;
classStack.addStack(userInput);
break;
case 2: cout<<"\n\n\t Your deleted value is: \t"<<classStack.deleteTop()<<endl; break;
case 3: classStack.sortingStack(); break;
case 4: classStack.topStack(); break;
case 5: classStack.displayStack(); break;
case 6:
cout<<"\n\n\t What are you searching for in your stack?\t";
cin>>searchThis;
classStack.searchingStack(searchThis);
break;
case 7:
done = true;
break;
}
}
}
int main ( ) {
bool done = false;
while ( !done ) {
int m_menu = showMainMenu();
switch (m_menu) {
case 1:
doStack();
break;
case 3:
done = true;
break;
}
}
}
i tried your code and did some alterations that you've said and when i run the program it doesn't go on loops like how i wanted to. and every choice i chose inside the stack and queue menu it just clears screen and doesn't show their output.
int showMainMenu() {
int m_menu;
system ("cls");
cout<<"\n*************************************";
cout<<"\n\t MAIN MENU\n";
cout<<"*************************************";
cout<<"\n\n\t (1) STACK \n\t (2) QUEUE \n\t (3) QUIT \n\n";
cout<<"Enter your choice:\t";
cin>>m_menu;
return m_menu;
}
int showStackMenu() {
int s_menu;
system ("cls");
while (1){
cout<<"\n*************************************"<<endl;
cout<<"\t STACK MENU\n";
cout<<"*************************************"<<endl;
cout<<"\n\t (1) Add \n\t (2) Delete \n\t (3) Sort \n\t (4) Top \n\t (5) Display \n\t (6) Search \n\t (7) Exit \n\n";
cout<<"Enter your choice: \t";
cin>>s_menu;
cout<<"-------------------------------------";
return s_menu; }
}
void doStack() {
int userInput,searchThis;
Stack classStack;
bool done = false;
while ( !done ) {
int s_menu = showStackMenu();
switch (s_menu) {
case 1:
cout<<"\n\n\t What do you want to put in your stack? \t";
cin>>userInput;
classStack.addStack(userInput);
break;
case 2: cout<<"\n\n\t Your deleted value is: \t"<<classStack.deleteTop()<<endl; break;
case 3: classStack.sortingStack(); break;
case 4: classStack.topStack(); break;
case 5: classStack.displayStack(); break;
case 6:
cout<<"\n\n\t What are you searching for in your stack?\t";
cin>>searchThis;
classStack.searchingStack(searchThis);
break;
case 7: done = true; break;
default: cout<<"\n\n\tInvalid input number!\n";
}
}
}
int showQueueMenu() {
int q_menu;
system("cls");
cout<<"\n*************************************";
cout<<"\n\t QUEUE MENU\n";
cout<<"*************************************";
cout<<"\n\n\t (1) Add \n\t (2) Delete \n\t (3) Sort \n\t (4) Display \n\t (5) Search \n\t (6) Exit \n\n";
cout<<"Enter your choice: \t";
cin>>q_menu;
cout<<"-------------------------------------";
return q_menu;
}
void doQueue(){
int userInput,searchThis;
Queue classQueue;
bool done = false;
while (!done) {
int q_menu = showQueueMenu();
switch (q_menu) {
case 1 :
cout<<"\n\n\t ADD\n\n\t What do you want to put in your queue? \t";
cin>>userInput;
classQueue.addQueue(userInput);
break;
case 2:
cout<<"\n\n\t Your deleted value is: \t"<<classQueue.deleteFront(); break;
case 3: classQueue.sortingQueue(); break;
case 4: classQueue.displayQueue(); break;
case 5:
cout<<"\n\n\t What are you searching for in your queue?\t";
cin>>searchThis;
classQueue.searchingQueue(searchThis);
break;
case 6: done = true; break;
default: cout<<"\n\n\tInvalid input number!\n";
}
}
}
int main ( ) {
bool done = false;
while ( !done ) {
int m_menu = showMainMenu();
switch (m_menu) {
case 1: doStack(); break;
case 2: doQueue(); break;
case 3: done = true; break;
}
}
}
To start with when providing code it is best and very helpful to provide a complete program. Meaning all the header files, Code for any header files that you write and any input file if the that may be needed. An input file does not have to be large, but it does need to contain any record that is giving a problem.
Given some time you will come to understand that seeplus can not use system("cls"); and that is why his output will be different from yours.
No worries. Sorry for the delay I had to go out for awhile.
I see that you have green checked the post, but if you want to go over your code click on my name and send me a Private Message that I can reply to and I will explain the problems I found in you original code.