help getting !true bool to break out of program

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2005
Posts: 10
Reputation: notdumb is an unknown quantity at this point 
Solved Threads: 0
notdumb notdumb is offline Offline
Newbie Poster

help getting !true bool to break out of program

 
0
  #1
Feb 16th, 2005
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, 1 views)
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 27
Reputation: odee is an unknown quantity at this point 
Solved Threads: 0
odee odee is offline Offline
Light Poster

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

 
0
  #2
Feb 16th, 2005
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;

}
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 27
Reputation: odee is an unknown quantity at this point 
Solved Threads: 0
odee odee is offline Offline
Light Poster

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

 
0
  #3
Feb 16th, 2005
or if you still want your orignal do while loop, change the condition inside the while... like this one:

  1. do {
  2.  
  3. // statement
  4.  
  5. } while(done==false);
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 10
Reputation: notdumb is an unknown quantity at this point 
Solved Threads: 0
notdumb notdumb is offline Offline
Newbie Poster

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

 
0
  #4
Feb 16th, 2005
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC