Bank Teller Program

I Have to Make a Code for School about A Bank Teller Program and it is not working everytime that I try to run the program. Every time I run the program it does not keep the data that I am trying to collect and it does not run the other cout sstatements. What am I doing wrong?


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
int main()
{
	double name;
	int account;
	int deposit;
	int withdrawl;
	int money = 10000;
	int balance;
	int n = 0;

	cout << "Please Enter Your Full Name: " << endl;
	cin >> name;
	cout << "Hello: " << name << endl;
	n++;

	cout << "Please Enter Your Bank Account Number: " << endl;
	cin >> account;
	n++;

	cout << "Please Enter the Amount of Money You Want to Deposit: " << endl;
	cin >> deposit;
	n++;

	cout << "Please Enter the Amount of Money You Want to Withdrawl: " << endl;
	cin >> withdrawl;
	n++;

	balance = money + deposit - withdrawl;

	if (n = 4) {
		cout << "Hello" << name << " Your Account is: " << account << "And Your Total Balance is: " << balance << "And You Deposited: " << deposit << "And You Withdrawled: " << withdrawl << endl;
	}
	else {
		cout << "Please Enter Your Full Name: " << endl;
		cin >> name;
		n++;

		cout << "Please Enter Your Bank Account Number: " << endl;
		cin >> account;
		n++;

		cout << "Please Enter the Amount of Money You Want to Deposit: " << endl;
		cin >> deposit;
		n++;

		cout << "Please Enter the Amount of Money You Want to Withdrawl: " << endl;
		cin >> withdrawl;
		n++;
	}
	_getch();
	return 0;
}


It doesn't work whenever I try to put in a name. Is there something that I am missing or is it very obvious and I am being dumb. Also When I put Nwb's answer into my code it did not solve anything just made it run the same way as it did. I don't know what to do.


'Lab 6.exe' (Win32): Loaded 'C:\Users\Sri\Documents\Lab 6\Lab 6\Debug\Lab 6.exe'. Symbols loaded.
'Lab 6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'Lab 6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'Lab 6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'Lab 6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp140d.dll'. Cannot find or open the PDB file.
'Lab 6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\vcruntime140d.dll'. Cannot find or open the PDB file.
'Lab 6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbased.dll'. Cannot find or open the PDB file.
'Lab 6.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbased.dll'. Cannot find or open the PDB file.
'Lab 6.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\ucrtbased.dll'
The thread 0xb10 has exited with code -1073741510 (0xc000013a).
The thread 0x2f10 has exited with code -1073741510 (0xc000013a).
The thread 0x2c5c has exited with code -1073741510 (0xc000013a).
The program '[9080] Lab 6.exe' has exited with code -1073741510 (0xc000013a).
Last edited on
if (n = 4) will always be true. All cin statements will be executed so if you want to validate you must use while loops and check the inputs and check for cin's fail state if(!cin) {}
name should be either a string or a char name[]

When you type a non digit to cin, it will go into fail state. So keep that in mind. You can use cin.clear() to make cin work again, but remember to flush the input stream because it will still have those characters previously taken.

_getch(); is a MVS function, use cin.get(); instead.


You can put this block
1
2
3
4
5
while(!cin) {
cin.clear();
cin.ignore(INT_MAX, '\n') // or your favorite method to clear the input buffer
cout << "try again";
}

below the cin statements that take integer or double (cin won't fail for string because string takes all supported characters).

cin fails for int and double because these variables can only hold digits.


Last edited on
Topic archived. No new replies allowed.