Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <string>
- #include <iostream>
- using namespace std;
- string Users[3];
- string passwords[3];
- int balances[3];
- bool locked[3];
- int currentUser;
- int currentBalance;
- int withdraw(int amountToWithdraw)
- {
- return currentBalance - amountToWithdraw;
- }
- int deposit(int amountToDeposit)
- {
- return currentBalance + amountToDeposit;
- }
- int checkBalance()
- {
- return currentBalance;
- }
- int main()
- {
- Users[0] = "User0";
- Users[1] = "User1";
- Users[2] = "User2";
- passwords[0] = "Password0";
- passwords[1] = "Password1";
- passwords[2] = "Password2";
- balances[0] = 0;
- balances[1] = 0;
- balances[2] = 0;
- locked[0] = false;
- locked[1] = false;
- locked[2] = false;
- string Username = "";
- int i = 0;
- bool isAuthenticated = false;
- cout << "Please login." << endl << "Username: ";
- cin >> Username;
- while (Username != Users[i])
- {
- for (i = 0; i < 3; i++)
- {
- if (Username == Users[i])
- {
- currentUser = i;
- break;
- }
- }
- if (Username == Users[i])
- {
- break;
- }
- cout << "Invalid Username! Try Again!" << endl;
- cin >> Username;
- }
- while (Username == Users[i])
- {
- for (int j = 0; j < 3; j++)
- {
- string passwordInput;
- cout << "Please Enter your Password for " << Username << endl << "Password: ";
- cin >> passwordInput;
- if (passwordInput == passwords[currentUser])
- {
- isAuthenticated = true;
- break;
- }
- else {
- cout << "Password Incorrect! You have " << 2 - j << " attempts remaining" << endl;
- continue;
- }
- }
- if (!(isAuthenticated))
- {
- locked[currentUser] = true;
- cout << "You have entered your password too many times and your account is now locked!" << endl;
- cout << "Please contact your local system administrator at 860-687-4097" << endl;
- cout << "Thank you, have a nice day" << endl;
- return 0;
- }
- else {
- break;
- }
- }
- cout << "Welcome to the University of Hartford Automated Teller Machine (ATM) " << Users[currentUser] << endl << "Please select an option from the ones listed below:" << endl;
- string userSelection;
- currentBalance = balances[currentUser];
- while (isAuthenticated)
- {
- cout << "Deposit Money (D)" << endl << "Withdraw Money (W)" << endl << "Check Balance (C)" << endl << "Exit (E)" << endl;
- cin >> userSelection;
- if (userSelection == "D")
- {
- int amountToDeposit;
- cout << "Enter how much money you'd like to deposit:" << endl;
- cin >> amountToDeposit;
- if (amountToDeposit > 0)
- {
- currentBalance = deposit(amountToDeposit);
- cout << "Amount successfully deposited! Your current balance is now: " << currentBalance << endl;
- }
- else
- {
- cout << "Improper amount entered please select another option." << endl;
- }
- }
- else if (userSelection == "W")
- {
- int amountToWithdraw;
- cout << "Enter how much money you'd like to withdraw:" << endl;
- cin >> amountToWithdraw;
- if (amountToWithdraw <= currentBalance)
- {
- currentBalance = withdraw(amountToWithdraw);
- cout << "Dispensing Money." << endl << "Your current balance is now: " << currentBalance << endl;
- }
- else
- {
- cout << "Improper amount entered please select another option." << endl;
- }
- }
- else if (userSelection == "C")
- {
- cout << "Your current balance is: " << checkBalance() << endl;
- }
- else if (userSelection == "E")
- {
- isAuthenticated = false;
- cout << "Thank you, have a great day " << Users[currentUser] << "!" << endl;
- break;
- }
- else {
- cout << "Input not recognized! Please try again." << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement