title: C++ Banking application not holding more than one account
body: <p>Hello I've been working on a C++ banking application that should be able to hold more than one account with all the related field's. I have come across a few issues: </p>
  
  <ul>
  <li>When displaying account info in Display or ShowInfo functions, the first letter of the first name and the middle initial wont show up.</li>
  <li>When creating an account only the most recent account is able to be searched for and displayed in display data. I know that an array is needed for this to be possible, I'm just not sure if implemented this correctly. </li>
  </ul>
  
  <p>Thanks for the help. Any input is appreciated!</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;conio.h&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  class BankAccount{
      double Balance = 0.0;
      char ans;
      public:struct Name{
          char Last_Name[50];
          char First_Name[50];
          char Middle_Initial[5];
      }Name;
      public:struct Account{
          char Type[1];
          int Account_Number;
      }Account;
      public:
      void CreateAccount();
      void Withdraw();
      void Deposit();
      void Display();
      void ShowInfo();
      int Menu();
  
  };
  
  void BankAccount::CreateAccount(){
      do
      {
          cout &lt;&lt; "\nEnter account number: ";
          cin &gt;&gt; Account.Account_Number;
          cout &lt;&lt; "\nEnter the last name for the account: ";
          cin.ignore();
          cin.getline(Name.Last_Name, 50);
          cout &lt;&lt; "\nEnter the first name for the account: ";
          cin.ignore();
          cin.getline(Name.First_Name, 50);
          cout &lt;&lt; "\nEnter the Middle initial for the account: ";
          cin.ignore();
          cin.getline(Name.Middle_Initial, 5);
          cout &lt;&lt; "\nEnter the type of account (C/S) : ";
          cin &gt;&gt; Account.Type;
          cout &lt;&lt; "\nEnter the initial balance of the account: ";
          cin &gt;&gt; Balance;
          cout &lt;&lt; "\n\nAccount Created.";
          cout &lt;&lt; "\n\nCreate new account? (Y/N) : ";
          cin &gt;&gt; ans;
  
          while (ans != 'Y' &amp;&amp; ans != 'N'){
              cout &lt;&lt; "Invalid input. Create new account? (Y/N) : ";
              cin &gt;&gt; ans;
          }
          cout &lt;&lt; endl;
      } while (ans != 'N');
  };
  void BankAccount::Withdraw(){
      int actNum;
      double amount;
      cout &lt;&lt; "Enter the account number for the account that you wish to withdraw funds: ";
      cin &gt;&gt; actNum;
      if (actNum == Account.Account_Number){
          cout &lt;&lt; "Enter the amount you would like to withdraw: ";
          cin &gt;&gt; amount;
          Balance = Balance - amount;
      }
      else if (actNum != Account.Account_Number){
          cout &lt;&lt; "No account found under that number! Try again!";
      }
  
  }
  void BankAccount::Deposit(){
      int actNum;
      double amount;
      cout &lt;&lt; "Enter the account number for the account that you wish to deposit funds: ";
      cin &gt;&gt; actNum;
      if (actNum == Account.Account_Number){
          cout &lt;&lt; "Enter the amount you would like to deposit: ";
          cin &gt;&gt; amount;
          Balance = Balance + amount;
      }
      else if (actNum != Account.Account_Number){
          cout &lt;&lt; "No account found under that number! Try again!";
      }
  }
  void BankAccount::Display(){
      int actNum;
      cout &lt;&lt; "Enter the account number for the account that you wish to display account information for: ";
      cin &gt;&gt; actNum;
      if (actNum == Account.Account_Number){
          cout &lt;&lt; "Account details for " &lt;&lt; Name.First_Name &lt;&lt; " " &lt;&lt; Name.Middle_Initial &lt;&lt; " " &lt;&lt; Name.Last_Name &lt;&lt; "'s account: " &lt;&lt; endl;
          cout &lt;&lt; "Account Number: " &lt;&lt; Account.Account_Number &lt;&lt; endl;
          cout &lt;&lt; "Account Type (Checking / Savings): " &lt;&lt; Account.Type &lt;&lt; endl;
          cout &lt;&lt; "Account Balance:  $" &lt;&lt; Balance &lt;&lt; endl;
      }
      else if (actNum != Account.Account_Number){
          cout &lt;&lt; "No account found under that number! Try again!";
      }
  
  }
  void BankAccount::ShowInfo(){
      cout &lt;&lt; "Account details for " &lt;&lt; Name.First_Name &lt;&lt; " " &lt;&lt; Name.Middle_Initial &lt;&lt; " " &lt;&lt; Name.Last_Name &lt;&lt; "'s account: " &lt;&lt; endl;
      cout &lt;&lt; "Account Number: " &lt;&lt; Account.Account_Number &lt;&lt; endl;
      cout &lt;&lt; "Account Type (Checking / Savings): " &lt;&lt; Account.Type &lt;&lt; endl;
      cout &lt;&lt; "Account Balance:  $" &lt;&lt; Balance &lt;&lt; endl;    
  
  }
  
  int main(int argc, char *argv){
      BankAccount ob;
      char ch;
  
      cout &lt;&lt; "Welcome to Console Banking Application V 1.0!";
      cout &lt;&lt; "\nSelect an item from the list below by entering the corresponding letter.";
      do{
          cout &lt;&lt; "\n\n A. Create Account \n B. Withdraw \n C. Deposit \n D. Show Account Details \n\n Q. Exit Application\n\n";
          ch = ob.Menu();
          switch (ch){
          case 'A':
          case 'a': ob.CreateAccount();
              ob.ShowInfo();
              break;
          case 'B': 
          case 'b': ob.Withdraw();
              break;
          case 'C':
          case 'c': ob.Deposit();
              break;
          case 'D':
          case 'd': ob.Display();
              break;
          case 'Q':
          case 'q': ob.ShowInfo();
                    exit(1);
              break;
          }
  
      } while (1);
  }
  int BankAccount::Menu(){
      char ch;
      cout &lt;&lt; "Select an option: ";
      cin &gt;&gt; ch;
      return ch;
  }
  </code></pre>