Hi all, I am having trouble trying to create a bank account program. I have I think all the defined headers and have the functions I need. But I am struggling with writting the program to create 2 accounts. 1 account lets say account number 123 will have a balance starting with 10 and then other account 943 will have the default balance which is zero.
How do I create these accounts with define intial balances and then how could I loop through first using defined deposit and then the withdrawal for each account.
Thanks
How would I do that? And then I would need to loop through. So I would create a ACCT then initiate a balance then loop through applying a deposit and then withdrawal and provide an ending balance. Then I would need to do this again with a new account. Then SUM both accounts.
account.h
------------
Line 25: You're declaring a deposit function that takes no arguments, then calls another deposit function (which doesn't exist) and passes 3. This makes no sense. Your declaration must match the implementation in the .cpp file (line 25).
Line 30: Ditto for Withdraw().
main.cpp
-----------
Line 9-10: This is not the proper way to instantiate you account class. 1) You must name the class. 2) You must give each object a different name (or place the objects in an array or vector as previously suggested. 3) You have no constructor for your class that takes 2 arguments.
Ok so this is what I now have. So looking into arrays. I think I need to perform a multidimensional array to define acctnum and balance. Such as I defined {acctnum=121, balance=""} by default the balance would be 0, and then I want to define another account {acctnum=32, balance=32}. With each of these I then want to perfrom a deposit to an account and a with drawal from an each. I want to do this for both.
test
*So this where I am lost. So I have the 2 accounts. Now I need to take the first account with deposit and perform a withdrawal of some amount and then a deposit of some amount. Then go to second deposit some amount and then deposit some amount. Then display intial deposit, then after withdrawal and after second deposit and what is account is after these actions.
So, first: The type of m_acctnum is int. Do not pass a string.
That's not the way arrays work. You don't need a 2-dimensional array. What you need is a 1-dimensional array where you can access the 2 member variables:
#include <iostream>
class account
{
...
//----------------------------------------------------
//deposit
void deposit(float amt){
m_balance += amt;
}
...
private:
//----------------------------------------------------
//account number
int m_acctnum;
//----------------------------------------------------
//balance
double m_balance;
};
int main(){
account a_array[] = { // Note: a_array
{44421, 20},
{55531, 30}
};
for (int i = 0; i < 2; ++i)
{
a_array[i].deposit(100); // Note: a_array[i].
}
return 0;
}
So if you implement a constructor and you want to initialize it like above you need at least one constructor that takes two parameter [for initializing both member variable m_balance and m_acctnum]: