help finishing program

Under class SavingsAccount i have a variable called balance, under the main function i created a switch statement, and every time i choose to deposit into savings account it goes under balance. But what i am trying to do is be able to choose to deposit into savings account more than once. So if i choose deposit and place $100 as balance and then i want to choose deposit again and place
$50, how can i make it that the balance ends up to $150. Also if i want to make more deposits. 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
//Esteban Efigenio
//Assignment 10 Course Project

 #include <iostream>
 #include <iomanip>
 using namespace std;


class BankAccount {   //name of class
public:
   double balance;
   double withdrawal;
 
   int MonthlyDepCount;
   int MonthlyWdCount;
   float AnnualIntRate;
   double MonthlySvcCh;
   double MonthlyIntRate;
   double MonthlyInt;
             
   BankAccount(){balance=0;}
       ~BankAccount(){};
   virtual void withdraw ();
   virtual void deposit();
   virtual void calcInt();
   virtual void monthlyProc(){
     }
};


class savingsAccount: public BankAccount {
public:
 
    savingsAccount(double balance=0){};
   ~savingsAccount(){};
  

 void deposit()
   {
        MonthlyDepCount=0;
   cout<<"Enter amount of money to deposit into Savings Account:"<<endl;
   cin>>balance ;
   if(balance>=25)
       {Active==1;
   MonthlyDepCount+=1;
   }
   else
   {
       cout<<"Account is Inactive"<<endl;
       system("pause");
   }
   }
   void withdraw()
   {
      MonthlyWdCount=0;
    cout<<"Enter amount of money to withdraw from Savings Account:"<<endl;
    cin>>withdrawal;
    if(withdrawal>balance || Active!=1)
        {
            cout<<"Not sufficient Funds"<<endl;
            system("pause");
        }
    else
        {
        balance-=withdrawal;
       
        MonthlyWdCount+=1;
       
        }
   
   }
 
 

   void monthlyProc()
   {
       MonthlySvcCh=0;
        cout<<"Service Charges:\t";
  if (MonthlyWdCount<4)
  cout<<"0.0";
  else (MonthlySvcCh==1+MonthlyWdCount);
  {
    cout<<MonthlySvcCh;
  }
   }

   void calcInt()
   {
       float AnnualIntRate=.05;
       balance=balance;
     MonthlyIntRate = AnnualIntRate / 12;
    MonthlyInt = balance * MonthlyIntRate;
    double balance1 = balance + MonthlyInt;
    cout<<"Ending Balance:\t"<<setprecision(2)<<fixed<<balance1<<endl;
      
   }

protected:             
   enum Status
   {
       Active = 1,
       Inactive
   };
   Status status;
};

class checkingAccount : public BankAccount {
public:
 
    checkingAccount(double balance=0){};
   ~checkingAccount(){};
 

    void deposit ()
    {
        MonthlyDepCount=0;
    cout<<"Enter amount of money to deposit into Checking Account:"<<endl;
    cin>>balance;
    MonthlyDepCount+=1;
    }

    void withdraw ()
    {
        MonthlyWdCount=0;
        if (balance<=0)
            {
                cout<<"You have no funds a service charge of $15.00 will be charged"<<endl;
            balance-=15;
            system("pause");
       
        }
        else
    cout<<"Enter amount of money to withdraw from Checking Account:"<<endl;
    cin>>withdrawal;
    MonthlyWdCount+=1;
    }
   

   void monthlyProc(){
       MonthlyWdCount+=1;
       if (balance<=0)
           {
               MonthlySvcCh=15;
               cout<<"Service Charges:\t";
               cout<<MonthlySvcCh;
               balance-=MonthlySvcCh;
       }
       else
       {
       MonthlySvcCh=5+ .10;
      
        cout<<"Service Charges:\t";
        cout<<MonthlySvcCh;
       
    double totWithdraw=withdrawal+MonthlySvcCh;
    balance-=totWithdraw;
       }
   }
   void calcInt()
   {
       if (balance<=0)
           cout<<"Ending Balance:\t"<<setprecision(2)<<fixed<<"-15.00"<<endl;
       else
       {
       float AnnualIntRate=.05;
       balance=balance;
     MonthlyIntRate = AnnualIntRate / 12;
    MonthlyInt = balance * MonthlyIntRate;
    double balance1 = balance + MonthlyInt;
    cout<<"Ending Balance:\t"<<setprecision(2)<<fixed<<balance1<<endl;
       }
   }


protected:
   double fees;
};





void BankAccount::withdraw () {}
 
 
void BankAccount::deposit () {}

void BankAccount::calcInt (void) {
}

char choice;

void main()
{
      BankAccount a;
      savingsAccount sa;
      checkingAccount ca;
  
 
  
      cout<<"\n\n\n";
      cout<<"*********WELCOME TO EFIGENIO'S BANK ACCOUNT SYSTEM***********"<<endl;
      cout<<"\n\n";
   
    
   

     char choice;
     mainmenu:
  
        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)
  
            {
                  case '1':
                     sa.deposit();
                     goto mainmenu;
                  case '2':
                     ca.deposit();
                     goto mainmenu;
                  case '3':
                     sa.withdraw();
                     goto mainmenu;
                  case '4':
                     ca.withdraw();
                     goto mainmenu;
                  case '5':
                      cout<<"SAVINGS ACCOUNT MONTHLY STATISTICS:"<<endl;
                  
              

                     cout<<"Withdrawals:\t"<<sa.MonthlyWdCount<<endl;
                      cout<<"Deposits:\t"<<sa.MonthlyDepCount<<endl;
                      sa.monthlyProc();
                      cout<<endl;
                      sa.calcInt();            
                      system("pause");
                      cout<<endl;
                    
                      cout<<"CHECKING ACCOUNT MONTHLY STATISTICS:"<<endl;
                      cout<<"Withdrawals:\t"<<ca.MonthlyWdCount<<  endl;
                      cout<<"Deposits:\t"<<ca.MonthlyDepCount<<endl;
                      ca.monthlyProc();
                      cout<<endl;
                      ca.calcInt();        
                      system("pause");
                   

                  case'6':
                    
                                     
                     default:
                     cout<<"Invalid menu item...Please re-enter your choice"<<endl;
                     break;
                     system("pause");
            }
    }
        
    }
 
     cout<<endl;
 
   
}
closed account (DSLq5Di1)
This should be obvious no? store input in a temporary variable, then add that to your balance..
This code overwrites the previous balance:

1
2
cout<<"Enter amount of money to deposit into Savings Account:"<<endl;
cin>>balance ;


What you should do instead is read in the new deposit, and then add that deposit to the balance:

1
2
3
4
5
double newDeposit;
cout<<"Enter amount of money to deposit into Savings Account:"<<endl;
cin>>newDeposit;
...
balance += newDeposit;


Also if i want to make more deposits

Simply calling sa.deposit(); should let you do the next deposit.

Also, goto has been deprecated since you can always use loops to do the same thing.

Consider using this instead of goto:

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
bool finished = false;

do
{
     char choice;
  
     cout<<"                    MAIN MENU"<<endl;
     ... //rest of main menu goes here
     cin>>choice;

     switch (choice)
     {
          case '1':
               sa.deposit();
               break; //no need for goto, let the loop handle it
          case '2':
               ca.deposit();
               break; //no need for goto, let the loop handle it

          ... //other cases

          case '6':
               finished = true;
               break;
          default:
          ... //default case
     }
} while(!finished);
Topic archived. No new replies allowed.