ATM Machine program not running still!

Pages: 12
My teacher broke the program and said that you cant allow the bank to be a negative balance within an account (checking or savings)... so i have been working on fixing it and havent found out how to do it... i make it so you can withdrawal more than bankBalance which gets underlines and switch equals and < and > around and its just now working
My teacher broke the program and said that you cant allow the bank to be a negative balance within an account (checking or savings)


Did he/she include that in the original problem specification? If not, then it is he and not you who is at fault! If something is omitted from the assignment question then you can't be marked down for it later.
I dont know im home now and forgot the sheet there...lol oops okay well he probably did and im not really in any placement to tell him he is wrong and i cant be marked off because he controls if i fail or not soooo ill post the code that i have that works but i still havent gotten it to work
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
//ATM.cpp
#include "ATMfinal.h"
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;

//bool exitProgram = false;
string bankName = "Livecchi National Credit Union";
bool exitProgram = false;

//initialize
bankAccount::bankAccount(string Name)
{
    bankBalance = 1000;
    setBankersName(Name);
}

//sets account name
void bankAccount::setBankersName(string name)
{
    bankName = name;
}
//get name
string bankAccount::getBankName()
{
    return bankName;
}
//set balance
double bankAccount::getBankBalance()
{
    return bankBalance;
}

void bankAccount::displayBalance()
{
    system("cls");
    cout << "Viewing account balance for account: \"" << getBankName() << "\"" << endl << endl;
    cout << endl << accountName << endl;
    for(int i = 0; i < 40; i++)
    cout << "~";
    cout << endl << fixed << "Bank Account Balance is: $" << setprecision(2) << bankBalance << endl << endl;
    cout << endl;
    system("PAUSE");
}
//transfer $
void bankAccount::transMoney2( bankAccount &bankAccount, double amount)
{
    depositMoney(bankAccount.withdrawlMoney(amount));
    cout << endl << fixed << setprecision(2) << accountName << "Balance is now: $" << endl << endl;
    cout << fixed << setprecision(2) << bankAccount.getBankName() << "Balance: $" << bankAccount.
    getBankBalance() << endl << endl;
    system("PAUSE");
}

double bankAccount::depositMoney(double amount)
{
    bankBalance += amount;
    cout << endl << fixed << setprecision(2) << accountName << "Balance is now: $" << bankBalance << endl << endl;
//    system("PAUSE");
    return amount;
}

double bankAccount::withdrawlMoney(double amount)
{
    bankBalance -= amount;
    cout << endl << fixed << setprecision(2) << accountName << "Balance is now: $" << bankBalance << endl << endl;
//    system("PAUSE");
    return amount;
}
void showBankMenu(bankAccount &account)
{
    int selected = 0;
    double amount;
    system("CLS");
    cout << "Manage a " << ::bankName << " account: \"" << account.getBankName() << "\"" << endl << endl;
    cout << endl;
    cout << "1- View Bank Account Balance" << endl;
    cout << "2- Deposit money to this Account" << endl;
    cout << "3- Withdrawl money from this Account" << endl;
    cout << "4- *Return to Main Menu*" << endl;
    cout << "Enter Choice: " << endl;
    cin >> selected;
    switch(selected)
    {
        case 1:
        account.displayBalance();
        break;
        case 2:
        cout << endl << "Enter deposit amount: $";
        cin >> amount;
        transCheck(account, amount, false);
        account.depositMoney(amount);
        break;
        case 3:
        cout << endl << "Enter withdrawl amount: ($" << account.getBankBalance() << " available): $";
        cin >> amount;
        transCheck(account, amount, true);
        account.withdrawlMoney(amount);
        break;
        case 4:
        break;
        default:
        cout << endl << "Invalid Entry please try again" << endl << endl;
        system("PAUSE");
        break;
    }
}

void manageBankAccounts(bankAccount &checking, bankAccount &savings)
{
    int selection = 0;
    system("cls");
    cout << "Welcome to Livecching \nNational Credit Union." << endl << endl;
	cout << endl;
    cout << "1- Manage checking account" << endl;
    cout << "2- Manage savings account" << endl;
    cout << "3- Transfer Money" << endl;
    cout << "4- Exit " << endl;
    cout << "Enter Selection: ";
    cin >> selection;
    switch(selection)
    {
        case 1:
			showBankMenu(checking);
			break;
        case 2:
			showBankMenu(savings);
			break;
        case 3:
			transMenu(checking, savings);
			break;
        case 4:
			::exitProgram = true;
			break;
        default:
			cout << endl << "Invalid entry please try again" << endl << endl;
			system("PAUSE");
			break;
    }
}

void transMenu(bankAccount &account1, bankAccount& account2)
{
    int selection;
    double transAmount = 0.00;
    system("CLS");
    cout << "Transfer money between account: " << account1.getBankName() << endl << endl;
    cout << endl;
    
    cout << "1- Transfer from Checking Account" << " to " << "Savings Account" << endl;
    
    cout << "2- Transfer from Savings Account" << " to " << "Checking Account" << endl;
    
    cout << "3- Back to Main Menu" << endl;
    
    cout << endl << "Enter Selection: ";
    cin >> selection;
    switch(selection)
    {
        case 1:
			cout << endl << "Enter amount of transfer ($" << account1.getBankBalance() << " available): $";
			cin >> transAmount;
			transCheck(account1, transAmount, true);
			account1.transMoney2(account2, transAmount);
			break;
        case 2:
			cout << endl << "Enter amount of transfer ($" << account2.getBankBalance() << " available): $";
			cin >> transAmount;
			transCheck(account2, transAmount, true);
			account2.transMoney2(account1, transAmount);
			break;
        case 3:
			break;
        default:
			cout << endl << "Invalid entry please try again" << endl << endl;
			system("PAUSE");
			break;
    }
}
void transCheck(bankAccount& acct, double &amount, bool checkOverdrawl)
{
    if(fmod((amount * 100), 1) != 0.00)
    {
        cout << endl << "This entry is invalid. Cancelling..." << endl;
        amount = 0;
    }
    
    else if(amount < 0)
    {
        cout << endl << "Cannot transfer a Negative amount." << endl;
        amount = 0;
    }
    else
    {
        cout << endl << " Transaction Processing " << endl;
    }
}

bool getProgStat()
{
    return ::exitProgram;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//main
#include <iostream>
#include <string>
#include "ATMfinal.h"
using namespace std;

int main()
{
	bankAccount checking("Checking Account");
	bankAccount savings("Savings Account");

	do
	{
		manageBankAccounts(checking, savings);
		system("CLS");
		cin.clear();
		cin.ignore(80, '\n');
	}while(getProgStat() == false);
}


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
#include <string>
using namespace std;

class bankAccount
{
public:
	bankAccount(string);
	string getBankName();
	double getBankBalance();
	void account1();
	void account2();
	void setBankersName(string);
	double withdrawlMoney(double);
	double depositMoney(double);
	void transMoney2(bankAccount &, double);
	void displayBalance();
private:
	string accountName;
	double bankBalance;
};

void showBankMenu(bankAccount &);
void manageBankAccounts(bankAccount &, bankAccount &);
void transMenu(bankAccount &, bankAccount &);
void transCheck(bankAccount&, double &, bool);
bool getProgStat();


he wants it email today... but i am not sure if he is even in his office today lol but basically i cant let the program put out a negative number from transfering to much money or withdrawaling to much
Well, check that the account being debited has sufficient funds in it before the transfer. If it has, then go ahead with the transfer, if it hasn't then tell the user and don't debit the account. Very simple really.
I have no idea how to do that cant I just set the max value that can be withdrawn equal to the amount left in the account?
Well, say you have a variable, we'll call it 'balance' of type 'double', and its current value is say '1100.000000' and you attempt to withdraw say '1099.99' would you expect to be able to do so under your rules? Then say you have the same variable called 'balance' that holds the same value and you then attempt to withdraw '1100.01' from it, again under your rules what would you expect the outcome to be?
Last edited on
.01 and - .01 would be the output?
.01 and - .01 would be the output?


What???? I thought under "your rules" you weren't allowed to exceed the current account limit? So if the balance was 1100.000000 and you attempted to withdraw 1099.99 this would be allowed and thus the account would have 0.01 in its balance. On the other hand if you had 1100.000000 in the account and attempted to withdraw 1100.01 this shouldn't be allowed so the user would be given a suitable message i.e. "You cannot withdraw 1100.01 as the account only has 1100.00 available funds, please try again" and the balance would remain at 1100.0000000 until a valid withdrawal attempt was made. That's just plain logic, isn't it?
Topic archived. No new replies allowed.
Pages: 12