Need assistance not adding over a certain value

I'm currently writing an ATM program and it's only supposed to allow a maximum withdrawal of $300. For some reason, I CAN NOT figure this out, I've probably tried 30 different variations and I can't seem to figure it out, although I have come close.
If the amount is over 300, the transaction should not take place and it should print the PrintError2 message. If there are insufficient funds; the PrintError1 function is called.
This is the final part of my program and I'm just flat out stuck on it.

Thanks


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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
void ATM :: Withdrawal (int money, string account, string transaction)
{


	
	 CurrentWithdrawalAmount +=money;
	if (CurrentWithdrawalAmount > 300)
		PrintError2();	

if (CurrentWithdrawalAmount < 300)
	{
	if (account == "Savings")
	{
	if (SavingsBalance >= money)
		{
		SavingsBalance -= money;
		PrintReceipt (money, account, transaction);
		}
	       else
			PrintError1();
	}
		
		
	
	
	if (account == "Checking")
	{
	if (CheckingBalance >= money)
		{
		CheckingBalance -= money;
		PrintReceipt (money, account, transaction);	
		}
	       else
			PrintError1();
	}
	}

//else
	//PrintError2();

	


}

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
31
32
33
34
void ATM :: Withdrawal (int money, string account, string transaction)
{


	
	 CurrentWithdrawalAmount +=money;
	if (CurrentWithdrawalAmount > 300)
        {
		PrintError2();	
        }
        else  
	{
	        if (account == "Savings")
	        { 
	              if (SavingsBalance >= money)
		     {
		            SavingsBalance -= money;
		            PrintReceipt (money, account, transaction);
		     }
	             else
			  PrintError1();
	        }
		else if (account == "Checking")
	        {
	                if (CheckingBalance >= money)
		        {
		                CheckingBalance -= money;
		                PrintReceipt (money, account, transaction);	
		        }
	                else
			     PrintError1();
	         }
	}
}
Last edited on
Your code makes 100% sense. I had code almost identical to that too but I have the right output to compare it and it still comes out wrong.

I integrated your code and got this:
Welcome to the CS2020 ATM
----------------------------------------
[D] Deposit
[W] Withdrawal
[T] Transfer To
[Q] Done
----------------------------------------
Please enter a selection: S
----------------------------------------
Please enter a valid selection: Z
Please enter a valid selection: D
(C) Checking
(S) Savings
Make a selection: F
----------------------------------------
Please enter a valid selection: A
Please enter a valid selection: C
Please enter the amount of money (multiple of 10s) : 15
Value must be a multiple of 10, please enter again: -20
Value must be a positive number, please enter again: 500
----------------------------------------
Transaction Type: Deposit
         Account: Checking
          Amount: $500
     New Balance: $500
----------------------------------------
[D] Deposit
[W] Withdrawal
[T] Transfer To
[Q] Done
----------------------------------------
Please enter a selection: D
----------------------------------------
(C) Checking
(S) Savings
Make a selection: S
----------------------------------------
Please enter the amount of money (multiple of 10s) : 30
----------------------------------------
Transaction Type: Deposit
         Account: Savings
          Amount: $30
     New Balance: $230
----------------------------------------
[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
----------------------------------------
Transaction Type: Deposit
         Account: Checking
          Amount: $100
     New Balance: $600
----------------------------------------
[D] Deposit
[W] Withdrawal
[T] Transfer To
[Q] Done
----------------------------------------
Please enter a selection: W
----------------------------------------
(C) Checking
(S) Savings
Make a selection: C
----------------------------------------
Please enter the amount of money (multiple of 10s) : 50
----------------------------------------
Transaction Type: Withdrawal
         Account: Checking
          Amount: $50
     New Balance: $550
----------------------------------------
[D] Deposit
[W] Withdrawal
[T] Transfer To
[Q] Done
----------------------------------------
Please enter a selection: W
----------------------------------------
(C) Checking
(S) Savings
Make a selection: S
----------------------------------------
Please enter the amount of money (multiple of 10s) : 290
----------------------------------------
You have reached your daily withdrawal amount of $300.
----------------------------------------
[D] Deposit
[W] Withdrawal
[T] Transfer To
[Q] Done
----------------------------------------
Please enter a selection: W
----------------------------------------
(C) Checking
(S) Savings
Make a selection: S
----------------------------------------
Please enter the amount of money (multiple of 10s) : 90
----------------------------------------
You have reached your daily withdrawal amount of $300.
----------------------------------------
[D] Deposit
[W] Withdrawal
[T] Transfer To
[Q] Done
----------------------------------------
Please enter a selection: W
----------------------------------------
(C) Checking
(S) Savings
Make a selection: C
----------------------------------------
Please enter the amount of money (multiple of 10s) : 200
----------------------------------------
You have reached your daily withdrawal amount of $300.
----------------------------------------
[D] Deposit
[W] Withdrawal
[T] Transfer To
[Q] Done
----------------------------------------
Please enter a selection: T
----------------------------------------
(C) Checking
(S) Savings
Make a selection: C
----------------------------------------
Please enter the amount of money (multiple of 10s) : 500
----------------------------------------
You have exceeded your balance
----------------------------------------
[D] Deposit
[W] Withdrawal
[T] Transfer To
[Q] Done
----------------------------------------
Please enter a selection: T
----------------------------------------
(C) Checking
(S) Savings
Make a selection: S
----------------------------------------
Please enter the amount of money (multiple of 10s) : 800
----------------------------------------
You have exceeded your balance
----------------------------------------
[D] Deposit
[W] Withdrawal
[T] Transfer To
[Q] Done
----------------------------------------
Please enter a selection: T
----------------------------------------
(C) Checking
(S) Savings
Make a selection: C
----------------------------------------
Please enter the amount of money (multiple of 10s) : 100
----------------------------------------
Transaction Type: Transfer
         Account: Checking
          Amount: $100
     New Balance: $650
----------------------------------------
[D] Deposit
[W] Withdrawal
[T] Transfer To
[Q] Done
----------------------------------------
Please enter a selection: D
----------------------------------------
(C) Checking
(S) Savings
Make a selection: S
----------------------------------------
Please enter the amount of money (multiple of 10s) : 10
----------------------------------------
Transaction Type: Deposit
         Account: Savings
          Amount: $10
     New Balance: $240
----------------------------------------
[D] Deposit
[W] Withdrawal
[T] Transfer To
[Q] Done
----------------------------------------
Please enter a selection: W
----------------------------------------
(C) Checking
(S) Savings
Make a selection: C
----------------------------------------
Please enter the amount of money (multiple of 10s) : 110
----------------------------------------
You have reached your daily withdrawal amount of $300.
----------------------------------------
[D] Deposit
[W] Withdrawal
[T] Transfer To
[Q] Done
----------------------------------------
Please enter a selection: Q
----------------------------------------
Exiting program.......


And for reference, here's the correct output...
http://pastebin.com/93Wyvf9N
(the post was too long)
Last edited on
First question: is the Withdraw amount per account or per person? Depending on you answer, data tracking would be different than what I saw in the code section.

Next question how are you tracking current day?

the other suggestion make the daily amount max start at 300 and match it to the withdraw thinking like in the DailyAmount - value of transaction and then check to see if you have zero or not.

Debugging your situation might involve printing all the numbers for their current states at each transaction. This might give you the pattern of the problem you are looking for. My first thoughts a number isn't Initialized to a state.
Last edited on
The program is just for one account. We are also not tracking the current day, it's just assumed the program is used for only one day so it should be fairly simple, or so I thought.

I'll give that suggestion a try; I think I might be able to make that work somehow.
if you are saying that 'savings' and 'checking', each should have their own daily totals of withdraws, you are combining both in the same variable from the code above, which suggests you are saying per person, not account.

if you are saying that 'savings' and 'checking', each should have their own daily totals of withdraws, you are combining both in the same variable from the code above, which suggests you are saying per person, not account.


They shouldn't both have their own daily totals. The maximum amount is 300 total for both.
Topic archived. No new replies allowed.