954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

help getting !true bool to break out of program

I was attempting to initilize bool done to false, then have this program continue to give the user the option to do more check balance functions util they pressed exit, however, my program continues to cycle repeatedly, even after option 5 (EXIT) is entered. Please, some help on how to recode so that program breaks out after this selection. Thanks. Will

Attachments willucheckstry2.cpp (2.64KB)
notdumb
Newbie Poster
10 posts since Feb 2005
Reputation Points: 10
Solved Threads: 0
 

change do while into while... and initialize done = true instead of false. then when you press 5 (exit) change done = false to exit the loop...

int main ()
{

  double checking, savings;
  int choice;

  get_balances (checking, savings);

  bool done = true;

  while(done)  {
       display_menu ();
       cout << "Enter Choice: ";
       cin >> choice;
       
       switch (choice)
       {
            case TRANSFER:
            transfer (checking, savings);
            break;

            case WITHDRAW:
            withdraw (checking);
            break;

            case CHECK:
            withdraw (checking);
            break;

            case DEPOSIT:
            deposit (checking);
            break;

            case EXIT:
            done = false;
            break;
	     }

  display_balances (checking, savings);
  }
  
  return 0;

}
odee
Light Poster
27 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

or if you still want your orignal do while loop, change the condition inside the while... like this one:

do  {

// statement

} while(done==false);
odee
Light Poster
27 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

Thanks so much. It is awsome of people to give there time to coach learners on here. Waiting for replies from teachers can take days, as can staring at what tends to be simple problems hoping for a solution to jump onto the screen. I appriciate the help.--Will

notdumb
Newbie Poster
10 posts since Feb 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You