-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathATM_Booth.cpp
More file actions
115 lines (97 loc) · 2.95 KB
/
ATM_Booth.cpp
File metadata and controls
115 lines (97 loc) · 2.95 KB
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
#include <iostream>
#include <conio.h>
#include<fstream>
using namespace std;
void display()
{
cout << "=======Welcome to Adnan's ATM Booth======="<< endl;
cout << " 1. Check Balance" << endl;
cout << " 2. Deposit Money" << endl;
cout << " 3. Withdraw Money" << endl;
cout << " 4. Exit" << endl;
}
bool checkPin()
{
int correctPin = 1234;
int enteredPin;
int attempts = 0;
while (attempts < 3)
{
cout << "Enter your 4-digit PIN: ";
cin >> enteredPin;
if (enteredPin == correctPin)
{
return true;
}
else
{
cout << "Incorrect PIN. Try again." << endl;
attempts++;
}
}
cout << "Too many incorrect attempts. Exiting..." << endl;
return false;
}
int main()
{
int balance = 50000;
int option;
int deposit;
int withdraw;
ofstream myfile;
myfile.open("atm.txt", ios::out | ios::app);
if (!checkPin())
{
return 0;
}
while (true)
{
display();
cout << "Choose Option:"<<endl;
cin >> option;
system("cls");
switch (option)
{
case 1:
cout << "Your Balance Now: " << balance << endl;
myfile << "Current Balance: " << balance << endl;
break;
case 2:
cout << "Enter Deposit Amount: ";
cin >> deposit;
balance += deposit;
cout << "You have deposited: " << deposit << endl;
cout << "My Current Balance Now: " << balance << endl;
myfile << "Deposited Amount: " << deposit << endl;
myfile << "Current Balance: " << balance << endl;
break;
case 3:
cout << "Enter Withdraw Amount: ";
cin >> withdraw;
if (withdraw <= balance)
{
balance -= withdraw;
cout << "You have withdrawn: " << withdraw << endl;
cout << "My Current Balance Now: " << balance << endl;
myfile << "Withdrawn Amount: " << withdraw << endl;
myfile << "Current Balance: " << balance << endl;
}
else
{
cout << "Insufficient Balance!" << endl;
myfile << "Failed Withdrawal Attempt: " << withdraw << endl;
}
break;
case 4:
cout << "Thank you for using Adnan's ATM Booth!" << endl;
myfile << "Session Ended. Final Balance: " << balance << endl;
return 0;
default:
cout << "Wrong Input, please try again." << endl;
myfile << "Invalid Option Selected: " << option << endl;
}
cout << "Press any key to continue... ... ..." << endl;
}
myfile.close();
return 0;
}