Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.56 KB | None | 0 0
  1. #include <cmath>
  2. #include <string>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6. string Users[3];
  7. string passwords[3];
  8. int balances[3];
  9. bool locked[3];
  10. int currentUser;
  11. int currentBalance;
  12.  
  13. int withdraw(int amountToWithdraw)
  14. {
  15.     return currentBalance - amountToWithdraw;
  16. }
  17.  
  18. int deposit(int amountToDeposit)
  19. {
  20.     return currentBalance + amountToDeposit;
  21. }
  22.  
  23. int checkBalance()
  24. {
  25.     return currentBalance;
  26. }
  27.  
  28. int main()
  29. {
  30.     Users[0] = "User0";
  31.     Users[1] = "User1";
  32.     Users[2] = "User2";
  33.     passwords[0] = "Password0";
  34.     passwords[1] = "Password1";
  35.     passwords[2] = "Password2";
  36.     balances[0] = 0;
  37.     balances[1] = 0;
  38.     balances[2] = 0;
  39.     locked[0] = false;
  40.     locked[1] = false;
  41.     locked[2] = false;
  42.     string Username = "";
  43.     int i = 0;
  44.     bool isAuthenticated = false;
  45.     cout << "Please login." << endl << "Username: ";
  46.     cin >> Username;
  47.     while (Username != Users[i])
  48.     {
  49.         for (i = 0; i < 3; i++)
  50.         {
  51.             if (Username == Users[i])
  52.             {
  53.                 currentUser = i;
  54.                 break;
  55.             }
  56.         }
  57.         if (Username == Users[i])
  58.         {
  59.             break;
  60.         }
  61.         cout << "Invalid Username! Try Again!" << endl;
  62.         cin >> Username;
  63.     }
  64.    
  65.     while (Username == Users[i])
  66.     {
  67.         for (int j = 0; j < 3; j++)
  68.         {
  69.             string passwordInput;
  70.             cout << "Please Enter your Password for " << Username << endl << "Password: ";
  71.             cin >> passwordInput;
  72.             if (passwordInput == passwords[currentUser])
  73.             {
  74.                 isAuthenticated = true;
  75.                 break;
  76.             }
  77.             else {
  78.                 cout << "Password Incorrect! You have " << 2 - j << " attempts remaining" << endl;
  79.                 continue;
  80.             }
  81.         }
  82.         if (!(isAuthenticated))
  83.         {
  84.             locked[currentUser] = true;
  85.             cout << "You have entered your password too many times and your account is now locked!" << endl;
  86.             cout << "Please contact your local system administrator at 860-687-4097" << endl;
  87.             cout << "Thank you, have a nice day" << endl;
  88.             return 0;
  89.         }
  90.         else {
  91.             break;
  92.         }
  93.     }
  94.  
  95.     cout << "Welcome to the University of Hartford Automated Teller Machine (ATM) " << Users[currentUser] << endl << "Please select an option from the ones listed below:" << endl;
  96.     string userSelection;
  97.     currentBalance = balances[currentUser];
  98.     while (isAuthenticated)
  99.     {
  100.         cout << "Deposit Money (D)" << endl << "Withdraw Money (W)" << endl << "Check Balance (C)" << endl << "Exit (E)" << endl;
  101.         cin >> userSelection;
  102.         if (userSelection == "D")
  103.         {
  104.             int amountToDeposit;
  105.             cout << "Enter how much money you'd like to deposit:" << endl;
  106.             cin >> amountToDeposit;
  107.             if (amountToDeposit > 0)
  108.             {
  109.                 currentBalance = deposit(amountToDeposit);
  110.                 cout << "Amount successfully deposited! Your current balance is now: " << currentBalance << endl;
  111.             }
  112.             else
  113.             {
  114.                 cout << "Improper amount entered please select another option." << endl;
  115.             }
  116.         }
  117.         else if (userSelection == "W")
  118.         {
  119.             int amountToWithdraw;
  120.             cout << "Enter how much money you'd like to withdraw:" << endl;
  121.             cin >> amountToWithdraw;
  122.             if (amountToWithdraw <= currentBalance)
  123.             {
  124.                 currentBalance = withdraw(amountToWithdraw);
  125.                 cout << "Dispensing Money." << endl << "Your current balance is now: " << currentBalance << endl;
  126.             }
  127.             else
  128.             {
  129.                 cout << "Improper amount entered please select another option." << endl;
  130.             }
  131.         }
  132.         else if (userSelection == "C")
  133.         {
  134.             cout << "Your current balance is: " << checkBalance() << endl;
  135.         }
  136.         else if (userSelection == "E")
  137.         {
  138.             isAuthenticated = false;
  139.             cout << "Thank you, have a great day " << Users[currentUser] << "!" << endl;
  140.             break;
  141.         }
  142.         else {
  143.             cout << "Input not recognized! Please try again." << endl;
  144.         }
  145.     }
  146.  
  147.  
  148.     return 0;
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement