#include #include using namespace std; int selection, PIN_input = 0, attempts = 0; const int PIN = 1065, attempts_limit = 3; double balance = 100, money; // This assignment is worth 5 points // -2 if the pin number is not utilized as a constant const int sel_op1 = 1, sel_op2 = 2, sel_op3 = 3, sel_op4 = 4; const string option1 = "Withdraw", option2 = "Deposit", option3 = "Check Balance", option4 = "Exit"; int main() { cout << fixed << setprecision(2); cout << "Enter PIN number: "; while(PIN_input != PIN && attempts < attempts_limit) { if(attempts > 0) cout << "Wrong PIN. Try again: "; cin >> PIN_input; if(++attempts == attempts_limit && PIN_input != PIN) cout << "Wrong PIN. Ending session." << endl; } while(PIN_input == PIN && selection != sel_op4) { cout << "Welcome!" << endl << "1. " << option1 << endl << "2. " << option2 << endl << "3. " << option3 << endl << "4. " << option4 << endl << "Please select your option: "; cin >> selection; // bool flag = true; switch(selection) { case sel_op1: // Withdraw money //bool flag = true; // Cannot declare variables inside switch-case do { cout << "Amount to withdraw ($): "; cin >> money; cin.ignore(); if(money > balance) cout << "Withdrawal amount exceeds balance! " << "Available balance is $" << balance << ".\n"; /* else { balance -= money; flag = false; cout << "Your balance is now $" << balance << ".\n"; cout << "Press Enter to continue"; cin.get(); }*/ } while(money > balance /*&& flag*/); balance -= money; cout << "Your balance is now $" << balance << ".\n"; cout << "Press Enter to continue"; cin.get(); break; case sel_op2: // Deposit money cout << "Amount to deposit ($): "; cin >> money; cin.ignore(); balance += money; cout << "Your balance is now $" << balance << ".\n"; cout << "Press Enter to continue"; cin.get(); break; case sel_op3: // Check current balance cout << "Your current balance is $" << balance << ".\n"; cout << "Press Enter to continue"; cin.get(); break; case sel_op4: // Exit program cout << "Have a nice day!" << endl; break; default: cout << "Invalid option. Please try again.\n"; break; } } //if(PIN_input == PIN) // cout << "Have a nice day!" << endl; return 0; }