944,083 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3114
  • C++ RSS
Feb 16th, 2005
0

help getting !true bool to break out of program

Expand Post »
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
Attached Files
File Type: cpp willucheckstry2.cpp (2.6 KB, 17 views)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
notdumb is offline Offline
10 posts
since Feb 2005
Feb 16th, 2005
0

Re: help getting !true bool to break out of program

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;

}
Reputation Points: 10
Solved Threads: 0
Light Poster
odee is offline Offline
27 posts
since Dec 2004
Feb 16th, 2005
0

Re: help getting !true bool to break out of program

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

C++ Syntax (Toggle Plain Text)
  1. do {
  2.  
  3. // statement
  4.  
  5. } while(done==false);
Reputation Points: 10
Solved Threads: 0
Light Poster
odee is offline Offline
27 posts
since Dec 2004
Feb 16th, 2005
0

Re: help getting !true bool to break out of program

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
notdumb is offline Offline
10 posts
since Feb 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Sending email from c++ application
Next Thread in C++ Forum Timeline: Randomize number with OpenGL





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC