title: Bank Accounts Using Vectors (Deposit and Withdrawal)
body: <p>I am working on a project that should allow you to create 3 accounts of the form (Name,AccountNumber,Balance) and then gives you the following options:</p>
  
  <p>1) Add an account.</p>
  
  <p>2) Close and existing account.</p>
  
  <p>3) Deposit an amount.</p>
  
  <p>4) Withdraw an account</p>
  
  <p>5) No request.</p>
  
  <p>Up till now, I am able to successfully create 3 accounts, display them, add another account, display them again, delete an account and display them once again. However, I am having trouble figuring out a way to deposit or withdraw money from a specific account.
  So to be clear, my question is: How do I access the balance of a chosen account and deposit/withdraw an amount (keeping in mind that I am using vectors to save all accounts)?</p>
  
  <p>The following is my code:</p>
  
  <p>main.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include "bank.hpp"
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  #include &lt;stdlib.h&gt;
  using namespace std;
  
  void fillaccounts(vector&lt;bank&gt;&amp;);
  void printaccounts(const vector&lt;bank&gt;&amp;);
  void createaccount(vector&lt;bank&gt;&amp;);
  void depositaccount(vector&lt;bank&gt;&amp;);
  void deleteaccount (vector&lt;bank&gt;&amp;);
  
  int main() {
  
  vector&lt;bank&gt; mybank;
  
  fillaccounts(mybank);
  
  for (int i=0;i&lt;5;i++) {
  
  cout &lt;&lt; "Please choose one of the following requests: " &lt;&lt; endl;
  cout &lt;&lt; "(1) Create a new account." &lt;&lt; endl;
  cout &lt;&lt; "(2) Close an existing account." &lt;&lt; endl;
  cout &lt;&lt; "(3) Deposit an amount in one of your accounts." &lt;&lt; endl;
  cout &lt;&lt; "(4) Withdraw an amount from one of your accounts." &lt;&lt; endl;
  cout &lt;&lt; "(5) No request." &lt;&lt; endl;
  cout &lt;&lt; "Enter your choice here: " &lt;&lt; endl;
  
  int request;
  cin &gt;&gt; request;
  
  switch (request) {
      case 1:
          createaccount(mybank);
          printaccounts(mybank);
          break;
  
      case 2:
  
          deleteaccount(mybank);
          printaccounts(mybank);
          break;
  
      case 3:
  
          depositaccount(mybank);
          printaccounts(mybank);
          break;
  
      case 4:
  
          break;
  
      case 5:
  
          break;
  
  }
  }
  }
  
  
  void fillaccounts(vector&lt;bank&gt;&amp; newmybank) {
  
  string name;
  int accountnumber;
  double balance;
  
  for (int i=0; i&lt;3;i++) {
      cout &lt;&lt; "Enter your first name: " &lt;&lt; endl;
      cin &gt;&gt; name;
  
      cout &lt;&lt; "Enter account number: " &lt;&lt; endl;
      cin &gt;&gt; accountnumber;
  
      cout &lt;&lt; "Enter the amount you want to deposit: " &lt;&lt; endl;
      cin &gt;&gt; balance;
  
      bank newAccount(name, accountnumber,balance);
      newmybank.push_back(newAccount);
      cout &lt;&lt; endl;
  }
  cout &lt;&lt; endl;
  
  }
  
  void createaccount(vector&lt;bank&gt;&amp; newmybank) {
  
  string name;
  int accountnumber;
  double balance;
  
      cout &lt;&lt; "Enter your first name: " &lt;&lt; endl;
      cin &gt;&gt; name;
  
      cout &lt;&lt; "Enter account number: " &lt;&lt; endl;
      cin &gt;&gt; accountnumber;
  
      cout &lt;&lt; "Enter the amount you want to deposit: " &lt;&lt; endl;
      cin &gt;&gt; balance;
  
      bank newAccount(name,accountnumber,balance);
      newmybank.push_back(newAccount);
      cout &lt;&lt; endl;
  
  }
  
  
  void printaccounts(const vector&lt;bank&gt;&amp; newmybank) {
  
  for (unsigned int i=0; i&lt;newmybank.size();i++) {
  
      cout &lt;&lt; "(" &lt;&lt; newmybank[i].getname() &lt;&lt; "," &lt;&lt;    newmybank[i].getaccountnumber() &lt;&lt; "," &lt;&lt; newmybank[i].getbalance() &lt;&lt; ")" &lt;&lt; endl;
  
  }
  cout &lt;&lt; endl;
  }
  
  
  void deleteaccount(vector&lt;bank&gt;&amp; newmybank) {
  
  string name;
  
  cout &lt;&lt; "Please enter your name to delete your account: " &lt;&lt; endl;
  cin &gt;&gt; name;
  cout &lt;&lt; endl;
  
  for (int i=0; i&lt;newmybank.size(); i++) {
  
      if (newmybank[i].newname == name) {
  
          newmybank.erase(newmybank.begin()+i);
  
      }
  }
  }
  </code></pre>
  
  <p>Bank.cpp</p>
  
  <pre><code>#include "Bank.hpp"
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  bank::bank() {
  
  newname=' ';
  newaccountnumber=0;
  newbalance=0.0;
  }
  
  bank::bank(string name,int accnum,double amount) {
  newname=name;
  newaccountnumber=accnum;
  newbalance=amount;
  }
  
  string bank::getname() const {
  return newname;
  }
  
  int bank::getaccountnumber() const {
  return newaccountnumber;
  }
  
  double bank::getbalance() const {
  return newbalance;
  }
  
  void bank::setname(string name) {
  newname=name;
  }
  
  void bank::setaccountnumber(int accountnumber) {
  newaccountnumber=accountnumber;
  }
  
  void bank::setbalance(double balance) {
  newbalance=balance;
  }
  </code></pre>
  
  <p>Bank.hpp</p>
  
  <pre><code>class bank {
  
  
  public:
  
  string newname;
  int newaccountnumber;
  double newbalance;
  
  bank(); //Constructor
  
  bank(string,int,double); //Overload Constructor
  
  string getname() const;
  int getaccountnumber() const;
  double getbalance() const;
  void setname(string);
  void setaccountnumber(int);
  void setbalance(double);
  
  };
  </code></pre>
  
  <p>Any advice on how to follow up?
  Thank you guys!</p>