I'm having some trouble with my ATM program, I currently don't have all of the functions included but I'm getting some errors that I'm not sure how to fix.
We're just now learning classes and since I have no previous experience with them, writing and debugging the program is difficult for me.
You have 2 declarations for the same variable 'account'.
1. As a member variable
2. As a variable passed to the function.
Since deposit is a member function.
You have 2 declarations for the same variable 'account'.
1. As a member variable
2. As a variable passed to the function.
Since deposit is a member function.
Are you referring to my declaration in main? I know "account" has to be declared in main because my instructor put it there, maybe I could name it something else in the class?
I'd really like to clear up these specific issues:
aprog4.cpp:107: error: 'SavingsBalance' was not declared in this scope
aprog4.cpp:131: error: 'CheckingBalance' was not declared in this scope
aprog4.cpp: In function 'int main()':
aprog4.cpp:173: error: no matching function for call to 'ATM::ATM(int, int)'
aprog4.cpp:32: note: candidates are: ATM::ATM()
aprog4.cpp:10: note: ATM::ATM(const ATM&)
I think I could probably figure the rest out if I get these problems solved.
aprog4.cpp:107: error: 'SavingsBalance' was not declared in this scope
aprog4.cpp:131: error: 'CheckingBalance' was not declared in this scope
You have no member variable of function void TransferTo with those names. You have to reference the class for that. If Henry is properly declared (and passed, which in this case it's not, so it will throw an out of scope error or SegFault), then use: if (Henry.SavingsBalance >= transmoney)
and if (Henry.CheckingBalance >= transmoney)
For:
aprog4.cpp: In function 'int main()':
aprog4.cpp:173: error: no matching function for call to 'ATM::ATM(int, int)'
aprog4.cpp:32: note: candidates are: ATM::ATM()
aprog4.cpp:10: note: ATM::ATM(const ATM&)
The constructor does not take arguments, so this: ATM Henry(200,-200);
should be: ATM Henry();
ATM::ATM(int a, int b)
{
CurrentWithdrawalAmount = 0;
SavingsBalance = a;
Checking Balance = b;
}
EDIT: Also, since you changed Void TransferTo() to Void ATM::TransferTo(), you no longer need Henry.CheckingBalance or Henry.SavingsBalance, they should be changed back to simply CheckingBalance and SavingsBalance.
Remove all the 'Henry' things from your ATM class. What are they supposed to be anyway?
Sorry, I should of been more clear here. Henry is essentially the object or the persons account. Don't ask me why, but it's supposed to be this way. I didn't write that part, my instructor did.
All of the errors that you posted most recently can be resolved by changing
EDIT: Also, since you changed Void TransferTo() to Void ATM::TransferTo(), you no longer need Henry.CheckingBalance or Henry.SavingsBalance, they should be changed back to simply CheckingBalance and SavingsBalance.
How could I get ATM :: ATM Henry (200, -200) to work as is? Like I said that part was written as is by my instructor so I think that's how he wants it done. What it's supposed to do is already have money put into the account.
...if that's the code the instructor gave you, I question the sanity of the instructor. Are you sure you copied it correctly?
He probably actually wanted something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
class ATM
{
// stuff goes here
ATM(int a, int b);
// stuff goes here
};
ATM::ATM(int a, int b)
{
// stuff goes here
}
int main()
{
ATM Henry(200, -200);
// stuff goes here
}
The code originally given cannot be made to work, as it is terrible syntax.
Edit: Removed extra whitespace and changed comments to C++-style. Also added a note about syntax.
How could I get ATM :: ATM Henry (200, -200) to work as is? Like I said that part was written as is by my instructor so I think that's how he wants it done. What it's supposed to do is already have money put into the account.
You can't. The constructor has to be passed variables, not absolute values. You declare the constructor like so:
1 2 3
ATM::ATM(int a, int b){
...
}
And then you create an instance of the object like so: ATM Henry(200, -200);
You're passing and returning a string that's not initialized. Might I recommend a char?
I've actually had that function working before. What's not working is the function where the user selects either the Savings or Checking account but as far as I know the function is nearly identical to the transaction function above.
I would use a char but the instructor wants use to enter a string and send it to a function where it will convert it into a word and return the word. I'm not really sure why.
It doesn't seem like transaction is being returned correctly. Every time I enter a correct transaction type it enters the while loop like it should where it calls both the AccountType function and InputMoney function. After the input money function runs it calls the AccountType function again when it should procede to the if() statements below.
I've tried cout << transaction; to see if I could test to see if the transaction was being passed back and nothing happens. Here's what happens in the program.
~/cs2020c$ a.out
Welcome to the CS2020 ATM
----------------------------------------
[D] Deposit
[W] Withdrawal
[T] Transfer To
[Q] Done
*******************
Please enter a selection: D
----------------------------------------
(C) Checking
(S) Savings
Make a selection:
C
----------------------------------------
Please enter the amount of money (multiple of 10s) : 100
(C) Checking
(S) Savings
Make a selection:
It should run this way..
~/cs2020c$ runprog4.exe
Welcome to the CS215 ATM
----------------------------------------
----------------------------------------
(D) Deposit
(W) Withdrawal
(T) Transfer To
(Q) Quit
----------------------------------------
Make a selection : D
D
----------------------------------------
----------------------------------------
(C) Checking Account
(S) Savings Account
----------------------------------------
Make a selection : C
C
----------------------------------------
Please enter the amount of money (multiple of 10s) : 100
100
----------------------------------------
Transaction Type: Deposit
Account: Checking
Amount : $ 100
New Balance : $ 100
----------------------------------------
----------------------------------------
(D) Deposit
(W) Withdrawal
(T) Transfer To
(Q) Quit
----------------------------------------
Make a selection :