Advertisement
Guest User

ATM

a guest
Nov 9th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4. #include <random>
  5. using namespace std;
  6.  
  7. int main();
  8. void gowhere();
  9. void deposit();
  10. void witdraw();
  11. void check();
  12.  
  13. double moneytotal = 0, addmoney, withdrawMoney;
  14. int menu1, upass, hmu = 1, userspot = 0;
  15.    
  16.     int a = 0, b = 0; //counters
  17.    
  18.     string username, password, newuser, newpass;
  19.    
  20.     string usernames[100] = {"Jason"};
  21.    
  22.     string passwords[100] = {"password"};
  23.    
  24. int main() {
  25.    
  26.    
  27.     cout << "=======Welcome======\n"
  28.          << "1. Login\n"
  29.          << "2. Create user\n"
  30.          << "3. Quit\n\n";
  31.          
  32.     cin >> menu1;
  33.          
  34.     switch (menu1) {
  35.         case 1: cout << "=======================\n"
  36.                      << "Please enter Username: ";
  37.                
  38.                 while (a == 0) {    
  39.                     cin >> username;
  40.                
  41.                     for (int x = 0 ; x < hmu ; x++) {
  42.                         if (username == usernames[x]) {
  43.                             upass = x;
  44.                             a += 1;
  45.                             break;
  46.                         }
  47.                         else if (username != usernames[x]) {
  48.                             continue;
  49.                         }
  50.                     }
  51.                 }
  52.         case 4: cout << "\nPlease enter password: ";
  53.                
  54.                 while (b == 0) {
  55.                     cin >> password;
  56.                    
  57.                     if (password == passwords[upass]) {
  58.                         cout << "\n" << "Welcome " << username << endl;
  59.                         b += 1;
  60.                     }
  61.                     else {
  62.                         cout << "Not correct please try again: ";
  63.                     }
  64.                 }
  65.             break;
  66.        
  67.         case 2: cout << "\nType your new username: ";
  68.                 cin >> newuser;
  69.                 hmu += 1;
  70.                 userspot += 1;
  71.                 usernames[userspot] = newuser;
  72.                
  73.                 cout << "\nEnter your password: ";
  74.                 cin >> newpass;
  75.                 passwords[userspot] = newpass;
  76.                 cout << "\nAll done\n";
  77.             break;
  78.        
  79.         case 3: cout << "Thank you for using ATM. Have a nice day";
  80.                 exit(0);
  81.                
  82.         case 5: for (int x = 0 ; x < 100 ; x++) {
  83.                     cout << usernames[x] << endl;
  84.                 }
  85.            
  86.     }
  87.     gowhere();
  88.    
  89. }
  90.  
  91. void gowhere() {
  92.     int menu2, moneytotal = 0;
  93.     cout << "\n====================\n\n"
  94.          << "What whould you like to do?\n"
  95.          << "1. Deposit\n"
  96.          << "2. Withdraw\n"
  97.          << "3. Check Balance\n"
  98.          << "4. Quit\n\n";
  99.          
  100.     cin >> menu2;
  101.    
  102.     switch (menu2) {
  103.         case 1: deposit();
  104.             break;
  105.         case 2: witdraw();
  106.             break;
  107.         case 3: check();
  108.             break;
  109.         case 4: main();
  110.                
  111.         default: cout << "Not a choice try again";
  112.                  gowhere();
  113.     }
  114. }
  115.  
  116. void deposit() {
  117.     cout << "\nDeposit how much: ";
  118.     cin >> addmoney;
  119.     moneytotal += addmoney;
  120.     cout << "\nDone\n";
  121.     gowhere();
  122. }
  123.  
  124. void witdraw() {
  125.     cout << "\nWithdraw how much: ";
  126.     cin >> withdrawMoney;
  127.     moneytotal -= withdrawMoney;
  128.     if (moneytotal < 0) {
  129.         moneytotal += withdrawMoney;
  130.         cout << "\nYou cannot withdraw that much\n";
  131.         gowhere();
  132.     }
  133.     else {
  134.         cout << "\nDone\n";
  135.         gowhere();
  136.     }
  137. }
  138.  
  139. void check() {
  140.     string goback;
  141.     cout << "\n====================\n"
  142.          << "Your total: " << moneytotal << "\n"
  143.          << "====================\n"
  144.          << "Type \'OK\' to go back: ";
  145.     cin >> goback;
  146.     if (goback == "OK") {
  147.         gowhere();
  148.     }
  149.     else {
  150.         gowhere();
  151.     }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement