bank account program

This is the main function of my homework assignment. What i am trying to do is loop the switch statement so it does not exit but instead allows me to choose another case and continuously display the menu. Any help would be appreciated. Thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
void main() 
{
	  BankAccount a;
      savingsAccount sa;
      checkingAccount ca;
    
   
    
      cout<<"\n\n\n";
      cout<<"*********WELCOME TO EFIGENIO'S BANK ACCOUNT SYSTEM***********"<<endl;
      cout<<"\n\n";
     
      
     
     void clear();
    
      char choice;
        cout<<"                    MAIN MENU"<<endl;
         cout<<""<<endl;
         cout<<""<<endl;
         cout<<"\t\t1:  Savings Account Deposit"<<endl;
         cout<<"\t\t2:  Checking Account Deposit"<<endl;
         cout<<"\t\t3:  Savings Account Withdrawal"<<endl;
		 cout<<"\t\t4:  Checking Account Withdrawal"<<endl;
         cout<<"\t\t5:  Update and Display Statistics:"<<endl;
		 cout<<"\t\t6:  EXIT:"<<endl;
		 cout<<"Make Selection using the numbers (1-6)"<<endl;
		 cin>>choice;

           switch (choice) 
    
            {
            int dep,wit;
                  case '1':

                     cout<<"Enter amount of money to deposit into Savings Account:"<<endl;
                     cin>>dep ;
					 sa.deposit(6700.44);
					 break;
					 
    
				  case '2':
					 cout<<"Enter amount of money to deposit into Checking Account:"<<endl;
                     cin>>dep;
					 ca.deposit(6700.44);
                     break;
    
                  case '3':
					  cout<<"How much do you want to withdraw from Savings Account:"<<endl;
                      cin>>wit;
					  sa.withdraw(5505.30);
                    break;
    
                  case '4':
					  cout<<"How much do you want to withdraw from Checking Account:"<<endl;
					  cin>>wit;
					  ca.withdraw(5505.30);
					  break;
				  case '5':
					  cout<<"SAVINGS ACCOUNT MONTHLY STATISTICS:"<<endl;
					
				

					 cout<<"Withdrawals:\t"<<sa.MonthlyWdCount<<endl;
					  cout<<"Deposits:\t"<<sa.MonthlyDepCount<<endl;
					  cout<<"Service Charges:\t"<<sa.MonthlySvcCh<< endl;
					  cout<<endl;
					  cout<<"Ending Balance:\t"<<sa.getbal()<<endl;
					  system("pause");
					  cout<<endl;
					  
					  cout<<"CHECKING ACCOUNT MONTHLY STATISTICS:"<<endl;
					  cout<<"Withdrawals:\t"<<ca.MonthlyWdCount<<  endl;
					  cout<<"Deposits:\t"<<ca.MonthlyDepCount<<endl;
					  cout<<"Service Charges:\t"<<ca.MonthlySvcCh<<endl;
					  cout<<endl;
					  cout<<"Ending Balance:\t"<<ca.getbal()<<endl;

					  system("pause");

				  case'6':
					 break;
					                   
					 default:
                     cout<<"Invalid menu item...Please re-enter your choice"<<endl;
                     break;
            }
   
     cout<<endl;
   
     
}

Last edited on
What you need to do to keep the menu options for a switch statement on screen is create a loop (my preference would be a "for" loop) that ends only when the user selects the exit case.

There are several ways of doing this. To me, the easiest way is to create a never-ending loop (something like for(;;)) that only gets broken (using break;) if the user selects the exit case. However, I have heard this is bad practice, although I am not entirely sure why.

The other option you have is to create a loop with the condition that it will continue as long as the exit case is not selected.
Last edited on
Topic archived. No new replies allowed.