Repository navigation
Expand file tree
/
Copy pathinternshiptask1.cpp
More file actions
100 lines (88 loc) · 2.92 KB
/
Copy pathinternshiptask1.cpp
File metadata and controls
100 lines (88 loc) · 2.92 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
#include <iostream>
#include <cstdlib>
using namespace std;
// ATM User Account
class ATM {
private:
int pin;
double balance;
public:
ATM(int userPin, double initialBalance) {
pin = userPin;
balance = initialBalance;
}
bool authenticate(int enteredPin) {
return enteredPin == pin;
}
void checkBalance() {
cout << "Your current balance is: Rs. " << balance << endl;
}
void deposit(double amount) {
if (amount > 0) {
balance += amount;
cout << "Successfully deposited Rs. " << amount << endl;
} else {
cout << "Invalid deposit amount." << endl;
}
}
void withdraw(double amount) {
if (amount <= 0) {
cout << "Invalid withdrawal amount." << endl;
} else if (amount > balance) {
cout << "Insufficient balance." << endl;
} else {
balance -= amount;
cout << "Successfully withdrew Rs. " << amount << endl;
}
}
};
int main() {
ATM user(1234, 10000.0); // Default PIN: 1234, Initial balance: Rs. 10000
int choice, pinTry;
int attempts = 0;
cout << "Welcome to Simple ATM Machine\n";
while (attempts < 3) {
cout << "Please enter your 4-digit PIN: ";
cin >> pinTry;
if (user.authenticate(pinTry)) {
while (true) {
cout << "\n========= ATM MENU =========\n";
cout << "1. Check Balance\n";
cout << "2. Deposit\n";
cout << "3. Withdraw\n";
cout << "4. Exit\n";
cout << "Choose an option: ";
cin >> choice;
switch (choice) {
case 1:
user.checkBalance();
break;
case 2: {
double depositAmount;
cout << "Enter amount to deposit: Rs. ";
cin >> depositAmount;
user.deposit(depositAmount);
break;
}
case 3: {
double withdrawAmount;
cout << "Enter amount to withdraw: Rs. ";
cin >> withdrawAmount;
user.withdraw(withdrawAmount);
break;
}
case 4:
cout << "Thank you for using the ATM. Goodbye!" << endl;
exit(0);
default:
cout << "Invalid choice. Please try again." << endl;
}
}
} else {
cout << "Incorrect PIN. Try again.\n";
attempts++;
}
}
cout << "Too many incorrect attempts. Your card is blocked.\n";
return 0;
}