title: C++ ATM Machine - A little assistance?
body: <p>Here's the complete code for my program and the problem stated below.</p>
  
  <p>This code is from my "virtual ATM machine" program which deals with customers depositing, checking balance and withdrawing money from their account. When I deposit the money, it displays that it gets deposited.. but "customer_actions()" being the main menu for the customers, when I go back on that screen and select the option to check balance, it displays as ZERO. </p>
  
  <p>Which means the values didn't get updated from the previous function. I wana get it to update when the user enters a deposit amount :/</p>
  
  <p>The problem is with the deposit function, im guessing. But I posted the complete program for your disposal. </p>
  
  <p>Thanks a lot guys :)</p>
  
  <p><strong>HEADER FILE:</strong></p>
  
  <pre><code>#ifndef bank
  #define bank
  
  
  using namespace std;
  
  
  class bankAccount
  {
      public:
          int accNo;
          int password;
  
          double balance;
          double withdrawamt;
          double depositamt;
  
          char name[20];
          char address[40];
          char username[10];
  
      public:
  
          double checkbalance();
          double deposit();
          double withdraw();
  
  
     /* public:
             bankAccount()
             {
                balance = 0;
             }    
  */
  };
  
  
  #endif
  </code></pre>
  
  <p><strong>COMPLETE PROGRAM up to now:</strong></p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;conio.h&gt;
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include "bank.h"
  
  using namespace std;
  using std::string;
  
  int logincheck (int ,int );
  double checkbal (double );
  int mainmenu(int );
  int customer_func();
  int officer_func();
  int enroll();
  int customer_actions();
  
  
  
  main() {
  
     double balance = 0, deposit = 0, withdraw = 0;
     int atmno;
     bankAccount b;
  
  
      system("cls");
      cout &lt;&lt; endl;
      cout &lt;&lt; "**************** Please select an ATM to continue *********************  \n"&lt;&lt;endl;;
      cout &lt;&lt; "-----------------------------------------------------------------------  \n";
      cout &lt;&lt; "|          ATM 1                  ATM 2                  ATM 3        |  \n";
      cout &lt;&lt; "-----------------------------------------------------------------------  \n"&lt;&lt;endl;
  
      cout &lt;&lt; "Enter ATM number: ";
      cin &gt;&gt; atmno;
  
      switch(atmno)
      {
          case 1: mainmenu(atmno); break;
          case 2: mainmenu(atmno); break;
          case 3: mainmenu(atmno); break;
      }
  }
  
     int mainmenu(int atmno)
     {
  
     int mainselection;
     system("cls");
     // Menu
     cout &lt;&lt; " -----------------------------------------------------------------------  \n";
     cout &lt;&lt; "|                               ATM Booth: " &lt;&lt; atmno &lt;&lt; "                            | \n";
     cout &lt;&lt; " ----------------- ----------------- ----------------- -----------------  \n";
     cout &lt;&lt; "                     Please Select option to continue:              \n" &lt;&lt; endl &lt;&lt; endl;
  
     cout &lt;&lt; "1) Customer Login    : Press 1" &lt;&lt; endl;
     cout &lt;&lt; "2) Officer Login     : Press 2" &lt;&lt; endl;
     cout &lt;&lt; "\nEnter option: ";
     cin &gt;&gt; mainselection;
  
     switch(mainselection)
     {
          case 1: customer_actions(); break;
          case 2: officer_func(); break;
     }
  
  }
  
      int customer_func()
      {
          int usr;
          int pss;
          bankAccount b;
  
  
             system("cls");
  
             cout &lt;&lt; " -----------------------------------------------------------------------  \n";
             cout &lt;&lt; "|                        AUTOMATED TELLER MACHINE                       | \n";
             cout &lt;&lt; " -----------------------------------------------------------------------  \n";
             cout &lt;&lt; "|           Please enter username and password to continue.             | \n";
             cout &lt;&lt; "|                                                                       | \n";
             cout &lt;&lt; "|                                                                       | \n";
             cout &lt;&lt; "|                                                                       | \n";
             cout &lt;&lt; " -----------------------------------------------------------------------  \n\n";
  
             cout &lt;&lt; "Username: ";
             cin &gt;&gt; usr;
  
             cout &lt;&lt; "Password: ";
  
             char c = ' ';
             while(c != 13) //Password masking with *
               {
                c = getch();
                pss += c;
                cout &lt;&lt; "*";
                }
  
             cin &gt;&gt; pss;
  
             //logincheck (usr, pss);
  
  
             getch();
          }
  
  /*
  int logincheck (int usr, int pss, bankAccount b)
  {
  
  
  
  
  }
  */
  
  
  
  int officer_func()
  {
      int officer_selection;
  system("cls");
     // officer menu
     cout &lt;&lt; " -----------------------------------------------------------------------  \n";
     cout &lt;&lt; "|                              Officer Menu                             | \n";
     cout &lt;&lt; " ----------------- ----------------- ----------------- -----------------  \n";
     cout &lt;&lt; "                     Please Select option to continue:              \n" &lt;&lt; endl &lt;&lt; endl;
  
     cout &lt;&lt; "1) Enroll new customer    : Press 1" &lt;&lt; endl;
     cout &lt;&lt; "2) Return home            : Press 2" &lt;&lt; endl;
     cout &lt;&lt; "\nEnter option: ";
     cin &gt;&gt; officer_selection;
  
  
     switch(officer_selection)
     {
          case 1: enroll(); break;
          case 2: main(); break;
     }
  
  
  
  }
  
  int enroll()
  {
      bankAccount b;
  
      system("cls");
  
     cout &lt;&lt; " -----------------------------------------------------------------------  \n";
     cout &lt;&lt; "|                          Enroll new customer                          | \n";
     cout &lt;&lt; " ----------------- ----------------- ----------------- -----------------  \n";
     cout &lt;&lt; "                     Please Select option to continue:              \n" &lt;&lt; endl &lt;&lt; endl;
  
  
  
     ofstream myfile;
  
     b.balance = 0;
     cout &lt;&lt; "Please enter customer name: " &lt;&lt; endl;
     cin &gt;&gt; b.name;
     cout &lt;&lt; "Please enter customer address: " &lt;&lt; endl;
     cin &gt;&gt; b.address;
     cout &lt;&lt; "Please enter customer Account Number: " &lt;&lt; endl;
     cin &gt;&gt; b.accNo;
     cout &lt;&lt; "Please enter username: (ONLY Numerals)" &lt;&lt; endl;
     cin &gt;&gt; b.username;
  
  
  
    //generatepass(bankAccount&amp; b);
  
  
  
     b.balance = 500000;
  
  
  
     int genpass = (b.accNo + 10);
     b.password = genpass;
  
     cout &lt;&lt; "\nPassword Generated: " &lt;&lt; genpass;
  
     myfile.open ("accounts.txt");
     myfile &lt;&lt; b.name &lt;&lt; endl &lt;&lt; b.address &lt;&lt; endl &lt;&lt; b.accNo &lt;&lt; endl &lt;&lt; b.username &lt;&lt; endl &lt;&lt; genpass &lt;&lt; endl &lt;&lt; b.balance;
     myfile.close();    
  
     cout &lt;&lt; "\n\nCustomer Account created! Press any key to save account file";
     getch();
  
     officer_func();
  
  }
  
  
  
  int customer_actions()
      {
            bankAccount b;
            int cust_selection;
            system("cls");
  
     cout &lt;&lt; " -----------------------------------------------------------------------  \n";
     cout &lt;&lt; "|                              Customer Menu                            | \n";
     cout &lt;&lt; " ----------------- ----------------- ----------------- -----------------  \n";
     cout &lt;&lt; "                     Please Select option to continue:              \n" &lt;&lt; endl &lt;&lt; endl;
  
     cout &lt;&lt; "1) Check balance    : Press 1" &lt;&lt; endl;
     cout &lt;&lt; "2) Withdraw Cash    : Press 2" &lt;&lt; endl;
     cout &lt;&lt; "3) Deposit Cash     : Press 3" &lt;&lt; endl;
     cout &lt;&lt; "4) Transfer Cash    : Press 4" &lt;&lt; endl;
     cout &lt;&lt; "5) Return home      : Press 5" &lt;&lt; endl;
     cout &lt;&lt; "\nEnter option: ";
     cin &gt;&gt; cust_selection;               
  
  
     switch(cust_selection)
     {
        case 1: b.checkbalance();   break;
        case 2: b.withdraw(); break;
        case 3: 
             for(int i=0;i&lt;=20;i++)
             {
                     b.deposit(); 
             break;
             }    
        case 4: break;
        case 5: main(); break;   
      }
  
  }
  
  
  double bankAccount::checkbalance()
  {
         system("cls");
         cout &lt;&lt; " -----------------------------------------------------------------------  \n";
         cout &lt;&lt; "|                              Customer Menu                            | \n";
         cout &lt;&lt; " ----------------- ----------------- ----------------- -----------------  \n";
  
         cout &lt;&lt; "\n\nYour balance is: " &lt;&lt; balance;
  
         getch();
         customer_actions();
         return balance;
  }
  
  
  double bankAccount::withdraw()
  {
         system("cls");
         cout &lt;&lt; " -----------------------------------------------------------------------  \n";
         cout &lt;&lt; "|                              Customer Menu                            | \n";
         cout &lt;&lt; " ----------------- ----------------- ----------------- -----------------  \n";
  
  
         cout &lt;&lt; "\n\nEnter Withdraw amount: ";
         cin &gt;&gt; withdrawamt;
         if (balance &gt; withdrawamt)
            balance = (balance - withdrawamt);
         else {
              cout &lt;&lt; "\nSorry you do not have enough money to make this transaction!";
              getch();
              customer_actions();
              }
  
         cout &lt;&lt; "\nYou have withdrawn " &lt;&lt; withdrawamt &lt;&lt; " successfully!";
         cout &lt;&lt;"\nYour balance is: " &lt;&lt; balance;
  
         getch();
         customer_actions();
         return balance;  
  }
  
  
  double bankAccount::deposit()
  {
  
  
         double amt;
  
         system("cls");
         cout &lt;&lt; " -----------------------------------------------------------------------  \n";
         cout &lt;&lt; "|                              Customer Menu                            | \n";
         cout &lt;&lt; " ----------------- ----------------- ----------------- -----------------  \n";
  
         cout &lt;&lt; "\n\nYOUR CURRENT BALANCE: " &lt;&lt; balance &lt;&lt; endl;
         cout &lt;&lt; "\nEnter amount to deposit: ";
         cin &gt;&gt; amt;
  
         balance = (balance + amt);
  
         cout &lt;&lt; "\nAmount depositted successfully!" &lt;&lt; endl;
         cout &lt;&lt;"\nYOUR CURRENT BALANCE: " &lt;&lt; balance;
  
         getch();
         return balance;
  
  }
  </code></pre>
  
  <p>The codes that I have 'commented' out are ones I used for testing or ones that I'm still working on, not really needed for now (Y)</p>