1#include <iostream>
2#include <string>
3#include <vector>
4#include <iomanip>
5#include <limits>
6
7struct ATMState {
8 double balance = 25000.0; // Initial balance in INR
9 const int correctPin = 5432;
10 std::vector<std::string> transactionHistory;
11};
12
13void logTransaction(ATMState& state, const std::string& note) {
14 state.transactionHistory.push_back(note);
15}
16
17bool authenticateUser(const ATMState& state) {
18 int enteredPin = 0;
19 int attempts = 0;
20 constexpr int MAX_ATTEMPTS = 3;
21
22 while (attempts < MAX_ATTEMPTS) {
23 std::cout << "Enter your 4-digit ATM PIN: ";
24 if (std::cin >> enteredPin) {
25 if (enteredPin == state.correctPin) {
26 std::cout << "✅ PIN Verified Successfully!\n";
27 return true;
28 }
29 }
30 ++attempts;
31 std::cerr << "❌ Incorrect PIN! Attempts remaining: " << (MAX_ATTEMPTS - attempts) << "\n";
32 std::cin.clear();
33 std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
34 }
35
36 std::cerr << "🚨 CARD BLOCKED: Too many incorrect attempts! Contact branch manager.\n";
37 return false;
38}
39
40int main() {
41 ATMState atm;
42
43 std::cout << "========================================\n";
44 std::cout << " MSK DIGITAL BANKING ATM PORTAL \n";
45 std::cout << "========================================\n";
46
47 if (!authenticateUser(atm)) {
48 return 1;
49 }
50
51 bool sessionActive = true;
52 while (sessionActive) {
53 std::cout << "\n----------------------------------------\n";
54 std::cout << "1. Check Account Balance\n";
55 std::cout << "2. Deposit Cash\n";
56 std::cout << "3. Withdraw Cash\n";
57 std::cout << "4. Mini-Statement (History)\n";
58 std::cout << "5. Eject Card & Exit\n";
59 std::cout << "Choose option (1-5): ";
60
61 int choice = 0;
62 if (!(std::cin >> choice)) {
63 std::cout << "Invalid input. Try again.\n";
64 std::cin.clear();
65 std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
66 continue;
67 }
68
69 switch (choice) {
70 case 1: {
71 std::cout << "💰 Current Account Balance: ₹" << std::fixed << std::setprecision(2) << atm.balance << "\n";
72 break;
73 }
74 case 2: {
75 double depositAmount = 0.0;
76 std::cout << "Enter amount to deposit: ₹";
77 if (std::cin >> depositAmount && depositAmount > 0) {
78 atm.balance += depositAmount;
79 logTransaction(atm, "Deposited: +₹" + std::to_string(static_cast<int>(depositAmount)));
80 std::cout << "✅ Successfully deposited ₹" << depositAmount << ". New Balance: ₹" << atm.balance << "\n";
81 } else {
82 std::cout << "[ERROR]: Invalid deposit amount.\n";
83 }
84 break;
85 }
86 case 3: {
87 double withdrawAmount = 0.0;
88 std::cout << "Enter amount to withdraw: ₹";
89 if (std::cin >> withdrawAmount && withdrawAmount > 0) {
90 if (withdrawAmount > atm.balance) {
91 std::cerr << "[ERROR]: Insufficient funds! Available balance: ₹" << atm.balance << "\n";
92 } else if ((atm.balance - withdrawAmount) < 1000.0) {
93 std::cerr << "[ERROR]: Withdrawal denied. Must maintain minimum balance of ₹1000.0\n";
94 } else {
95 atm.balance -= withdrawAmount;
96 logTransaction(atm, "Withdrew: -₹" + std::to_string(static_cast<int>(withdrawAmount)));
97 std::cout << "💵 Please collect your cash: ₹" << withdrawAmount << ". New Balance: ₹" << atm.balance << "\n";
98 }
99 } else {
100 std::cout << "[ERROR]: Invalid withdrawal amount.\n";
101 }
102 break;
103 }
104 case 4: {
105 std::cout << "\n📜 --- Mini-Statement (Recent Activity) ---\n";
106 if (atm.transactionHistory.empty()) {
107 std::cout << "No transactions in this session.\n";
108 } else {
109 for (const auto& entry : atm.transactionHistory) {
110 std::cout << " • " << entry << "\n";
111 }
112 }
113 break;
114 }
115 case 5: {
116 std::cout << "\n💳 Card Ejected. Thank you for banking with MSK Institute Digital Bank!\n";
117 sessionActive = false;
118 break;
119 }
120 default:
121 std::cout << "Invalid choice! Please select 1 through 5.\n";
122 break;
123 }
124 }
125
126 return 0;
127}