This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

strange issue, program not terminating properly when returning from sub-menu

 
Randy Smith
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi! Thank you for looking. I have a console menu where the program terminates normally through switch statements in mainmenu but when returning to mainmenu from sub-menu, i have to enter "0" twice to terminate the program from mainmenu. I checked everywhere, and everything look fine. this is very strange... Here's the simplified code. Am I doing anything incorrently? Any assistance is appreciated!

mainMenu(){

do {
int option;
boolean terminate=false;

print welcome shopper's world!
print 1. Add item to cart
print 2. remove item from cart
print 3. view cart
print 0. quit

print Please make a selection:

new scanner input object

switch (option)

case 1: addItem();
break();

case 2: removeItem();
break();

case 3: viewCart();
break();

case 0: println("Thank you for your business!");
terminate=true;
break();

default: print invalid option, try again!
break();

}while (!terminate);
}

addItem(){

if(true){
//do something here...

}

else{
mainmenu();
}


}

 
Angus Comber
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post code which actually compiles, otherwise any help would be pure guesswork. Instructions on how to reproduce error would also help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic