Shed some light on my ATM program?

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.

ANY help is greatly appreciated.

Here's the errors I'm getting:
See below
See Below





Last edited on
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.


Thanks
You forgot "ATM :: " in front of the function/method TransferTo name.

Tim S.
For:
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();
Last edited on
I have some questions regarding the ATM Henry(200,-200); statement. The comment left by my instructor says
//Declaration of the only class object used in this program
, what does this require me to do in the class?

I revised the code a bit, trying to figure things out.
Shortened for space




Besides the conversion warnings, here's what I'm getting.
Shortened
Last edited on
Remove all the 'Henry' things from your ATM class. What are they supposed to be anyway?
All of the errors that you posted most recently can be resolved by changing
1
2
3
4
5
6
ATM :: ATM Henry(200,-200)
{
SavingsBalance = a;
Checking Balance = b;

}

to
1
2
3
4
5
6
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.
Last edited on
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.
Last edited on
I didn't copy any of it, he gave us the file and yes, he is a little crazy but I'll try what you gave me a shot. Thanks.
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);
Okay, syntactically, I THINK I have everything correct. The problem now lies in the part starting with
while (transaction != "Quit")
where all the functions are called. You might be able just to point out the problem, but if you run it, this is what happens...


Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
string InputTransaction (string transaction)
{
	cout << "[D] Deposit" << endl;   
	cout << "[W] Withdrawal" << endl;  
	cout << "[T] Transfer To" << endl;
	cout << "[Q] Done" << endl;
	cout << "*******************" << endl; 
     cout << "Please enter a selection: ";
     cin >> transaction;
	cout << "----------------------------------------" <<endl;
	while (transaction != "D" && transaction != "W"  && transaction != "T" && transaction != "Q")
		{
			cout << "Please enter a valid selection: ";
			cin >> transaction;
		}
			if (transaction == "D")
				transaction == "Deposit";
			
			if (transaction == "W")
				transaction == "Withdrawal";

			if (transaction == "T")
				transaction == "Transfer";

			if (transaction == "Q")
				exit(0);

		
return transaction;
}


You're passing and returning a string that's not initialized. Might I recommend a char?
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.


EDIT: Figured it out.
Last edited on
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 : 




Am I passing things incorrectly?
Figured it out.
Last edited on
Topic archived. No new replies allowed.