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

Dani AI

Generated

Two short possibilities explain why the program keeps cycling after you enter the EXIT choice: the loop condition and the flag value are inverted, or input handling never updates choice because cin failed. ’s suggestion to flip the loop logic (or to initialize the boolean so the loop condition matches the flag) is on the right track, but it helps to look at a few other failure modes before changing structure.

Remember these concrete rules while debugging:

  • A break inside a switch exits only the switch, not the outer loop. To stop the loop you must set the loop-control flag (or return/break the loop directly) when EXIT is chosen.
  • If you use a do...while, make sure the initial boolean and the while(...) test agree (one common pattern is “run while not done” and set done = true on EXIT).
  • If cin >> choice fails (user types non-numeric text), choice will not change and the loop can repeat forever. Clear the error and discard the bad input before the next read.

Practical checks and a small input-recovery pattern to add:

  • Print choice and the flag after each loop iteration to watch what values change.
  • Confirm your EXIT constant really equals the number the menu prints (5).
  • Fix obvious copy/paste mistakes in the switch (for example, make sure the CHECK case calls the check-balance routine, not withdraw).
  • Use a simple input-recovery block like:
    if (!(cin >> choice)) {
    cin.clear();
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
    continue; // prompt again
    }

Checklist: align flag initialization with the loop condition, set the flag inside the EXIT case, validate and clear input, and add temporary debug prints. Those four steps will reveal whether the problem is logic inversion, input failure, or a typo in the switch.

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;

}

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

do  {

// statement

} while(done==false);

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.