Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot figure out how to do this code
    text
    copied!<p>I have been working on this project that simulates a bank account. The user can deposit, withdraw, and have all the withdraws and deposits displayed on the screen. At the top of the selection menu needs to be the current balance. Like so, SAVINGS : 100. And whenever I deposit money or withdraw money I need that balance to change to the correct amount. The amount starts at $100. If I deposit or withdraw money it will work perfectly the first time, but on the second time it gets reset back to $100 and then the transaction is done. How can I make the balance stay the correct amount without it resetting? This is a school project and I am not looking for someone to provide me the code. I am just seeking some tips or guidance in the right direction. Here is the code for my int main() :</p> <pre><code>int main () { saving sa; creditCard cca; checking ca; string n; int option; int exit = 1; int x = 1; do{ cout &lt;&lt; endl; cout &lt;&lt; "Checking Balance:" &lt;&lt; ca.getBalance() &lt;&lt; " " &lt;&lt; "Savings balance:" &lt;&lt; sa.getBalance() &lt;&lt; " " &lt;&lt; "Credit Card balance:" &lt;&lt; cca.getBalance() &lt;&lt; endl; cout &lt;&lt; endl; cout &lt;&lt; " (1) Savings Deposit " &lt;&lt; endl; cout &lt;&lt; " (2) Savings withdrawel " &lt;&lt; endl; cout &lt;&lt; " (3) Checking Deposit " &lt;&lt; endl; cout &lt;&lt; " (4) Write A Check " &lt;&lt; endl; cout &lt;&lt; " (5) Credit Card Payment " &lt;&lt; endl; cout &lt;&lt; " (6) Make A Charge " &lt;&lt; endl; cout &lt;&lt; " (7) Display Savings " &lt;&lt; endl; cout &lt;&lt; " (8) Display Checkings " &lt;&lt; endl; cout &lt;&lt; " (9) Display Credit Card " &lt;&lt; endl; cout &lt;&lt; " (0) Exit " &lt;&lt; endl; cin &gt;&gt; option; switch ( option ) { case 1 : { double SamtD; cout &lt;&lt; " Please enter how much you would like to deposit into savings " &lt;&lt; endl; cin &gt;&gt; SamtD; sa.makeDeposit(SamtD); break; }; case 2 : { int SamtW; cout &lt;&lt; " Please enter how much you would like to withdraw "&lt;&lt; endl; cin &gt;&gt; SamtW; sa.doWithdraw(SamtW); break; } case 3 : { double CamtD; cout &lt;&lt; " Please enter how much you would like to deposit into checkings " &lt;&lt; endl; cin &gt;&gt; CamtD; ca.makeDeposit(CamtD); break; } case 4 : { double CamtW; int chkNum; cout &lt;&lt; " Please enter how much you wrote on the check " &lt;&lt; endl; cin &gt;&gt; CamtW; cout &lt;&lt; " Please enter the check number " &lt;&lt; endl; cin &gt;&gt; chkNum; ca.writeCheck(chkNum, CamtW); break; } case 5 : { double CCmkP; cout &lt;&lt; " Please enter the amount you would like to deposit " &lt;&lt; endl; cin &gt;&gt; CCmkP; cca.makePayment(CCmkP); break; } case 6 : { double DoC; string Nm; cout &lt;&lt; " Please enter the amount charged to your credit card " &lt;&lt; endl; cin &gt;&gt; DoC; cout &lt;&lt; " Please enter where the charge was made " &lt;&lt; endl; cin &gt;&gt; Nm; getline(cin, Nm); cca.doCharge(Nm,DoC); break; } case 7 : { sa.display(); break; } case 8 : { ca.display(); break; } case 9 : { cca.display(); break; } case 0 : exit = 0; break; default : exit = 0; cout &lt;&lt; " ERROR "; } } while(exit==1); return 0; } </code></pre> <p>and here is were the balance is being set :</p> <pre><code>double curbalance = 100; void account::setBalanceD(double balance) // This is for deposit { itsBalance = balance; } void account::setBalanceW(double balance) // This is for withdraw { double newBalance = curBalance - balance; itsBalance = newBalance; } double account::getBalance() { return itsBalance; } </code></pre> <p>and here is the code that option 2 in my menu would be calling :</p> <p>int saving:: doWithdraw(int amount)</p> <pre><code>{ if (amount &gt; 0) { for (int i = 9; i != 0; i--) { last10withdraws[i] = last10withdraws[i-1]; } last10withdraws[0] = amount; setBalanceW(amount); } else { cout &lt;&lt; " ERROR. Number must be greater then zero. " &lt;&lt; endl; } return 0; } </code></pre> <p>Any ideas? I just cannot get the balance to remain accurate.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload