Advertisement
Guest User

Untitled

a guest
Nov 14th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. // function prototypes
  8. void printIntroMenu();
  9. void printMainMenu();
  10. void start();
  11. void login();
  12. void createAccount();
  13. void depositMoney();
  14. void withdrawMoney();
  15. void requestBalance();
  16.  
  17. // global variable (use this variable to store the user’s menu selection)
  18. int menuInput, input;
  19. string user = "ADMIN", pass = "admin", useri, passi;
  20. int login_access = 0;
  21. double money=0, amount;
  22.  
  23. int main() {
  24.     start();
  25. }
  26.  
  27. void printIntroMenu() {//mainmenu
  28.     cout << "Please select an option from the menu below:\n\n" << "1 -> Login\n" << "2 -> Create New Account\n" << "3 -> Quit\n\n" << ">";
  29.     cin >> menuInput;
  30. }
  31.  
  32. void printMainMenu() {
  33.     cout << "1 -> Deposit Money" << endl << "2 -> Withdraw Money" << endl << "3 -> Request Balance" << endl << "4 -> Quit" << endl << endl << ">" << endl;
  34.     cin >> input;
  35.     switch (input) {//switch statment to trigger additional functions
  36.             case 1://case is used like an if statement here to provide conditions. If the input = 1 , deposit money function will be called
  37.                 depositMoney();
  38.                 break;
  39.             case 2:
  40.                 withdrawMoney();
  41.                 break;
  42.             case 3:
  43.                 requestBalance();
  44.                 break;
  45.             case 4:
  46.                 cout << "Goodbye, please come again" << endl;
  47.         }
  48. }
  49.    
  50. void start() {
  51.         printIntroMenu();
  52.         switch (menuInput) {
  53.             case 1:
  54.                 login();
  55.                 break;
  56.             case 2:
  57.                 createAccount();
  58.                 start();
  59.                 break;
  60.             case 3:
  61.                 cout << "Goodbye!" << endl;
  62.         }
  63. }
  64.  
  65. void login() {
  66.     cout << "Username: ";
  67.     cin >> useri;
  68.     cout << "Password: ";
  69.     cin >> passi;
  70.  
  71.  
  72.     if (user == useri && pass == passi) {
  73.         cout << "Access Granted\n";
  74.         printMainMenu();
  75.         login_access++;
  76.     } else {
  77.         cout << "ACCESS DENIED";
  78.     }
  79. }
  80.  
  81. void createAccount() {
  82.     cout << "Input a new Username: ";
  83.     cin >> user;
  84.    
  85.     cout << "Input a new Password: ";
  86.     cin >> pass;
  87.     printIntroMenu();
  88. }
  89.  
  90. void depositMoney() {
  91.     cout << "How much do you want to deposit?";
  92.     cin >> amount;
  93.     money = amount + money;//simple counter to keep track of money
  94.     cout << "You deposited " << amount << " into your bank account." << endl;
  95.     printMainMenu();
  96. }
  97.  
  98. void withdrawMoney() {
  99.     cout << "How much do you want to withdraw?";
  100.     cin >> amount;
  101.     money = money - amount; //subtracts from the counter
  102.     cout << "You withdrew " << amount << " from your bank account." << endl;
  103.     printMainMenu();
  104. }
  105.  
  106. void requestBalance() {
  107.     cout << "You have " << amount << " in your account." << endl;
  108.     printMainMenu(); //brings users back to the main menu
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement