Bank System
Bank System
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm> // For transform
#include <cctype> // For tolower
struct Account {
string name;
double balance;
int pin; // Add PIN for each account
double CashOnHand = 0.0; // Global cash on hand (initially set to $10,000)
};
void ClearC() {
// system("cls"); // Avoid using system calls; platform-specific
cout << "\033[2J\033[1;1H"; // ANSI escape code to clear console screen (works on most
terminals)
}
void displayMenu() {
cout << "\n--- Banking System Menu ---\n";
cout << "1. Create Account\n";
cout << "2. Deposit Money\n";
cout << "3. Withdraw Money\n";
cout << "4. Check Balance\n";
cout << "5. Change PIN\n";
cout << "6. Exit\n";
cout << "Choose an option: ";
}
if (existingNameLower == nameLower) {
return true; // Account exists (case-insensitive)
}
}
return false; // Account does not exist
}
int main() {
char choice;
Account accounts[MAX_ACCOUNTS];
int accountCount = 0;
do {
ClearC();
displayMenu();
cin >> choice;
cin.ignore(); // To handle any leftover newline character
switch (choice) {
case '1': // Create Account
if (accountCount < MAX_ACCOUNTS) {
string name;
cout << "Enter account holder's name: ";
getline(cin, name);
cout << "Amount on hand: $";
cin >> accounts[accountCount].CashOnHand;
if (accountExists(accounts, accountCount, name)) {
cout << "You already have an account with this name!\n";
}
else {
accounts[accountCount].name = name;
accounts[accountCount].balance = 0.0; // Initial balance
cout << "Enter a 4-digit PIN: ";
cin >> accounts[accountCount].pin;
accountCount++;
cout << "Account created successfully!\n";
}
}
else {
cout << "Maximum account limit reached!\n";
}
break;
default:
cout << "Invalid choice! Please try again.\n";
}
return 0;
}