ATM code.

Hello, it's me again. Have some new stuff I need help with.

I can't backspace when inputting the pin. I want to be able to do so. How do I do it?
Can I also have the pin as an array? And how would I also go about doing that?

Thanks in advance~

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
#include <iostream>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <windows.h>
#include <unistd.h>
#include <cstdlib>
#include <sstream>

using namespace std;

int addition (int d, int e)
{
	int f;
	f = d + e;
	return f;
}

int subtraction (int g, int h)
{
	int i;
	i = g - h;
	return i;
}

int main(void)
{
	int a;
	float b = 10000;
	int c;
	int j;
	const int CR = 13;
	HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE); 
    DWORD mode = 0;
    GetConsoleMode(hStdin, &mode);
    SetConsoleMode(hStdin, mode & (~ENABLE_ECHO_INPUT));
	std::string s;

	retry:
	j = 0;
	s = "0";
	cout<< "***********************************************************\n";
	cout<< "*************Welcome to our simple ATM Machine*************\n";
	cout<< "***********************************************************\n";
	cout<< "Please enter your pincode: ";
    do
	{
		j = _getch();
		if (isdigit(j))
			{
				s += (char)j;
				cout << "*";
			}
	}
	while (j != CR);
  
	stringstream convert(s);
	if ( !(convert >> j) )
		j = 0;
	sleep (1);
	system ("CLS");
	
	if (j == 1234)
	{
		goto proceed;
	}
	else
	{
		system ("CLS");
		cout<< "Invalid pin.";
		sleep (2);
		system ("CLS");
		goto retry;
	}
	
	proceed:
	cout<< "\nSuccess!\nAccessing your data..........................";
	sleep (3);
	system ("CLS");
	
	repeat:
	cout<< "\n\nPlease select one of three options:\n";
	cout<< "[1] Balance Inquiry\n[2] Withdraw\n[3] Deposit\n\n";
	cout<< "Option selected: ";
	cin>> a;
	system ("CLS");
	
	if (a==1)
	{
		cout<< "\nYour current balance is: " << b;
	}
	else if (a==2)
	{
		cout<< "\nPlease enter how much you would like to withdraw: ";
		cin>> c;
		system ("CLS");
		if (c>b)
		{
			cout<< "\nError, insufficient balance.";
		}
		else if (c<=0)
		{
			cout<< "\nError, the amount cannot be less than 1.";
		}
		else
		{
		b = subtraction (b, c);
		cout<< "\nTransaction successful, your current remaining balance is: " << b;
		}
	}
	else if (a==3)
	{
		cout<< "\nPlease enter how much you would like to deposit: ";
		cin>> c;
		system ("CLS");
		if (c<=0)
		{
			cout<< "\nError, the amount cannot be less than 1.";
		}
		else
		{
			b = addition (b, c);
			cout<< "\nTansaction successful, your current balance is now: " << b;
		}
	}
	else
	{
		cout<< "\n\nInvalid choice.";
		goto repeat;
		return 0;
	}
	
	last:
	cout<< "\n\nWould you like to do something else?\n";
	cout<< "Select an option:\n\n";
	cout<< "[1] Yes\n[2] No\n\n" << "Option selected: ";
	cin>>c;
	system ("CLS");
	if (c==1)
	{
		goto repeat;
	}
	else
	{
		end:
		system ("CLS");
		cout<< "\nThank you for using group 2's simple ATM Machine!";
		return 0;
	}
}
Use SetConsoleCursorPosition(...) when you detect the backspace:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms686025%28v=vs.85%29.aspx
Topic archived. No new replies allowed.