Advertisement
HakdogForce

ATM MACHINE

Nov 22nd, 2018
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 17.32 KB | None | 0 0
  1. /*
  2. ATM PROGRAM BY : ALJAN A. PORQUILLO
  3. BSCSSE - N01
  4.  
  5. SUBMITTED TO: MRS. MAY D. SAN PABLO
  6. */
  7.  
  8. #include <iostream>
  9. #include <Windows.h>
  10. using namespace std;
  11.  
  12. // VARIABLE DECLARATIONS FOR NEW ACCOUNTS
  13. int a, b, y, z, x, cashin, balance = 0, passchoice, withdraw, cash , r, add_Bal, temp, password1 = 0, password[0], num5val = 0;
  14. char username[1000];
  15. char tempname[1000];
  16. int pin[100];
  17. int pin_check;
  18.  
  19. // PRE DEFINE VARIABLE DECLARATIONS FOR OLD ACCOUNTS
  20. char predefUser;
  21. int uPass;
  22. int uPin;
  23. int uName;
  24. int u_Balance = 1000000, uAdd_bal, u_Withdraw, u_Temp, u_Cash, u_Cashin, u_A, pintemp, cPin1, cPin2, s, w, q;
  25.  
  26. // PREDEFINED USER ID OF MAY
  27. int userPass = 333; // PREDEFINE USER PASSWORD
  28. int userPin = 1352; // PREDEFINE USER PIN
  29.  
  30. // FUNCTION PROTOTYPING
  31. int main();
  32. int new_Menu();
  33. int myTrademark();
  34. int reg_newUser();
  35. int timer();
  36. int menu();
  37. int exit();
  38. int reg_oldUser();
  39. int old_Menu();
  40. int backtoMenu2();
  41.  
  42. int myTrademark(){ // COMPANY NAME
  43.     cout << " ----------------------------------" << endl;
  44.     cout << "|        F O R C E  B A N K        |" << endl;
  45.     cout << "|                                  |" << endl;
  46.     cout << "|    Owned by: Aljan Porquillo     |" << endl;
  47.     cout << " ----------------------------------" << endl;
  48. }
  49.  
  50. int backtoMenu(){ // REDIRECTING FUNCTION FOR NEW ACCOUNTS
  51.     cout << "\nRedirecting. please wait...";
  52.     Sleep(3000);
  53.     cout << "\n";
  54. }
  55.  
  56. int backtoMenu2(){ // REDIRECTING FUNCTION FOR OLD ACCOUNTS
  57.     cout << "\nRedirecting. please wait...";
  58.     Sleep(3000);
  59.     cout << "\n";
  60.     return old_Menu();
  61. }
  62.  
  63. int user_Input(){ // MENU INPUT
  64.     myTrademark();
  65.     cout << "       [1] New User" << endl;
  66.     cout << "       [2] Registered User" << endl;
  67.     cout << "\n ----------------------------------" << endl;
  68.     cout << "Select user type: ";
  69.     cin >> x;
  70.  
  71.     if(x==1){
  72.     reg_newUser();
  73.     }
  74.  
  75.     if (x==2){
  76.     reg_oldUser();
  77.     }
  78.    
  79.     if(x > 2){
  80.         cout << "\n[Error]: You entered wrong input.\nwe're now redirecting you ";
  81.         system("pause");
  82.         system("cls");
  83.         return main();
  84.     }
  85. }
  86.  
  87. int new_reg(){ // NEW ACCOUNT DIRECTING TO REGISTERED USER
  88.     myTrademark();
  89.     cout << " " << endl;
  90.     cout << " ----------------------------------" << endl;
  91.     cout << "|            L O G I N             |" << endl;
  92.     cout << " ----------------------------------" << endl;
  93.     cout << "Enter Account name: ";
  94.     cin >> tempname;
  95.     cout << "Enter Password: ";
  96.     cin >> password[3];
  97.     cout << "Enter Pin: ";
  98.     cin >> pin[4];
  99.         if(tempname == username){
  100.             if(password[0] == password[3] || pin[2] || pin[0] == pin[4]){
  101.             cout << "Login successfully!" << endl;
  102.             cout << "\nRedirecting. please wait...";
  103.             Sleep(3000);
  104.             new_Menu();
  105.         }
  106.         else{
  107.         cout << "\n\nEither Account name, Password or Pin you've entered is incorrect." << endl;
  108.         backtoMenu();
  109.         system("cls");
  110.         user_Input();
  111.         }      
  112.     }
  113. }
  114.  
  115. int reg_newUser(){ // NEW USER
  116.             cout << "\n -------REGISTERING NEW USER-------" << endl;
  117.            
  118.             cout << "Username: ";
  119.             cin >> username;
  120.            
  121.             cout << " ----------------------------------" << endl;
  122.             cout << "|         Register your pin        |" << endl;
  123.             cout << " ----------------------------------" << endl;
  124.             cout << "Enter pin: ";
  125.             for(int i = 0; i < 1; i++){
  126.                 cin >> pin[0]; // pin 0 and pin 1 are same pin
  127.                 cout << " ----------------------------------" << endl;
  128.                 cout << "|            Verify Pin            |" << endl;
  129.                 cout << " ----------------------------------" << endl;
  130.                 cout << "Enter pin: ";
  131.                 for(int j = 1; j < 2; i++){
  132.                     cin >> pin[1]; // pin 1 and pin 0 are same pin
  133.                     break;
  134.                 }
  135.             }
  136.             if(pin[0] == pin[1]){
  137.                 cout << " ----------------------------------" << endl;
  138.                 cout << "|          Pin Verified!           |" << endl;
  139.                 cout << "|     You're now registered!       |" << endl;
  140.                 cout << " ----------------------------------" << endl;
  141.                 backtoMenu();
  142.                do{
  143.                 new_Menu();
  144.                }
  145.                while(true);
  146.             }
  147.             else{
  148.                 cout << "\n\nPin doesn't match!" << endl;
  149.                 backtoMenu();
  150.                 system("cls");
  151.                 myTrademark();
  152.                 reg_newUser();
  153.             }
  154. }
  155.  
  156. int reg_oldUser(){ // PRE DEFINED USER ACCOUNT
  157.     myTrademark();
  158.    
  159.     cout << " " << endl;
  160.     cout << " ----------------------------------" << endl;
  161.     cout << "|            L O G I N             |" << endl;
  162.     cout << " -------- Registered User ---------" << endl;
  163.     cout << "Pin: ";
  164.     cin >> uPin;
  165.     cout << "Pass: ";
  166.     cin >> uPass;
  167.    
  168.    
  169.     if(uPass == userPass){
  170.             if(userPin == uPin){
  171.                 cout << "\nLogin Successfully!" << endl;
  172.                 cout << "\nWelcome May!" << endl;
  173.                 cout << "Please wait a moment..." << endl;
  174.                 Sleep(3000);
  175.                 old_Menu();
  176.             }
  177.             else{
  178.                 cout << "\nError! wrong Pin" << endl;
  179.                 cout << "Redirecting. please wait..." << endl;
  180.                 Sleep(3000);
  181.                 return reg_oldUser();
  182.             }
  183.        
  184.     }
  185.     else{
  186.         cout << "\nError! No Account associated with this Pin and Password!\n" << endl;
  187.         cout << "Redirecting. please wait..." << endl;
  188.         Sleep(3000);
  189.         system("cls");
  190.         return reg_oldUser();
  191.     }
  192. }
  193.  
  194. int old_Menu(){ // OLD USER MENU
  195.     system("cls");
  196.     cout << " ----------------------------------" << endl;
  197.     cout << "|             M E N U              |" << endl;
  198.     cout << "|                                  |" << endl;
  199.     cout << "|          Select Process          |" << endl;
  200.     cout << " ----------------------------------" << endl;
  201.     cout << "[1] Deposit" << endl;
  202.     cout << "[2] Withdraw"<< endl;
  203.     cout << "[3] Balance Inquiry"<< endl;
  204.     cout << "[4] Change Pin" << endl;
  205.     cout << "[5] Logout" << endl;
  206.    
  207.     cout << "------------------------" << endl;
  208.     cout << "Choose process number: ";
  209.     cin >> x;
  210.    
  211.         if(x==1){
  212.             if(x==1){ // DEPOSIT
  213.                 system("cls");
  214.                 myTrademark();
  215.                 cout << "\nWelcome May!" << endl;
  216.                 cout << "   ---------+ DEPOSIT +----------\n" << endl;
  217.                 cout << "Balance: " << u_Balance << endl;
  218.                 cout << "\nEnter Amount to Deposit: ";
  219.                 cin >> uAdd_bal;
  220.                     u_Balance += uAdd_bal; // will add to current balance
  221.                         if(uAdd_bal > 0 || uAdd_bal != 0){
  222.                             cout << "------------------------------" << endl;
  223.                             cout << "\nYour deposit is successfully transacted!\n" << endl;
  224.                             cout << "Please wait a moment..." << endl;
  225.                             Sleep(3000);   
  226.                             return old_Menu();
  227.                         }
  228.                         else{
  229.                             cout << "\nNo Deposit has been made" << endl;
  230.                             cout << "Please wait a moment..." << endl;
  231.                             Sleep(3000);   
  232.                             return old_Menu();
  233.                         }
  234.                     }
  235.            
  236.             }
  237.            
  238.        
  239.         if(x==2){ // WITHDRAW
  240.             system("cls");
  241.             myTrademark();
  242.             cout << "  ---------+ WITHDRAW +----------\n" << endl;
  243.                 if(u_Balance > 0 || u_Balance != 0){
  244.                     cout << "Current balance: " << u_Balance << endl;
  245.                     cout << "********************************" << endl;
  246.                     cout << "\nWithdraw amount: ";
  247.                     cin >> u_Withdraw;
  248.                         if(u_Withdraw <= u_Balance){
  249.                             cout << "\n[SUCCESFULLY WITHDRAWED!]" << endl;
  250.                             cout << "--------------------------------" << endl;
  251.                                 u_Temp = u_Balance - u_Withdraw; // store to temporary variable in order to safely store current balance
  252.                             cout << "\nCurrent Balance " << u_Temp << endl;
  253.                                 u_Balance -= u_Withdraw; // Minus to current balance
  254.                             return backtoMenu2(); // return
  255.                            
  256.                     }
  257.                         else if(u_Withdraw > u_Balance){
  258.                             cout << "\nYou can't withdraw, you have insufficient funds" << endl;
  259.                             return backtoMenu2();
  260.                            
  261.                         }
  262.                 }
  263.                 else if(u_Withdraw == 0 || u_Withdraw < 0){
  264.                     cout << "   [YOU CAN'T WITHDRAW]" << endl;
  265.                     cout << "\nError: It seems you have insufficient enough balance.\nPlease top up." << endl;
  266.                     return backtoMenu2();
  267.                
  268.                 }
  269.         }
  270.        
  271.         if(x==3){
  272.             if(x==3){ // BALANCE INQUIRY
  273.             system("cls");
  274.             myTrademark();
  275.             cout << "  ------+ BALANCE INQUIRY +-------\n" << endl;
  276.                 if(uAdd_bal > 0 || u_Balance != 0 || u_Balance > 0){
  277.                     cout << "Current Balance " << u_Balance << endl;
  278.                     return backtoMenu2();
  279.                 }
  280.                 else if(uAdd_bal == 0){
  281.                     cout << "Your account has insufficient funds" << endl;
  282.                         while(true){
  283.                             cout << "\n============ Add Funds ============\n" << endl;
  284.                             cout << "Do you want to add funds" << endl;
  285.                             cout << "-----------------------------------\n" << endl;
  286.                             cout <<"[1] YES     [2] NO\n" << endl;
  287.                             cout << "-----------------------------------" << endl;
  288.                             cout << "Choose process number: ";
  289.                             cin >> z;
  290.  
  291.                             if(z==1){
  292.                                 cout << "Cash in amount: ";
  293.                                 cin >> cashin;
  294.  
  295.                                 u_Cashin += u_Balance;
  296.                                 u_A = u_Cash;
  297.                                 u_Balance = u_A;
  298.  
  299.                                 if(u_Cashin > 0 || u_Balance != 0){
  300.                                     cout << "\nYour deposit is successfully transacted!\n" << endl;
  301.                                     return backtoMenu2();
  302.                                 }
  303.                             }
  304.                            
  305.                             if(z==2){
  306.                                 return old_Menu();
  307.                             }
  308.                     }
  309.                 }
  310.                 else{
  311.                     cout << "Your Balance is: " << balance << endl;
  312.                     system("pause"); // return
  313.                 }
  314.         }
  315.     }
  316.    
  317.     if(x==4){ // CHANGE PIN
  318.         system("cls");
  319.         myTrademark();
  320.         cout << "   --------+ CHANGE PIN +--------\n" << endl;
  321.         cout << "Enter your pin: ";
  322.         cin >> pintemp;
  323.             if(pintemp == userPin){
  324.                
  325.                 cout << " ----------------------------------" << endl;
  326.                 cout << "|           Changing Pin           |" << endl;
  327.                 cout << " ----------------------------------" << endl;
  328.                    
  329.                 cout << "Enter pin: ";
  330.                 cin >> cPin1;
  331.                
  332.                 cout << "Enter Pin Again: ";
  333.                 cin >> cPin2;
  334.                
  335.                 if(cPin1 == cPin2){
  336.                     cout << "\nSuccessfully Pin Changed" << endl;
  337.                     cout << "\n[Note]: Account will Logout." << endl;
  338.                    
  339.                     // Swapping pin defined variables
  340.                    
  341.                     s = cPin1;
  342.                     q = s;
  343.                    
  344.                     userPin = q;
  345.                    
  346.                 }
  347.                 else{
  348.                     cout << "Pin Doesn't Matched! please try again." << endl;
  349.                     return backtoMenu2();
  350.                 }
  351.             }
  352.             else{
  353.                 cout << "Wrong Pin!";
  354.                 return backtoMenu2();
  355.             }
  356.            
  357.             cout << "\nRe-Login your account" << endl;
  358.             cout << "\nPlease wait a moment..." << endl;
  359.             Sleep(3000);
  360.             system("cls");
  361.             return reg_oldUser();
  362.        
  363.     }
  364.    
  365.     if(x==5){ // LOGOUT
  366.         system("cls");
  367.         cout << "Account will Logout!" << endl;
  368.         cout << "\nPlease wait a moment..." << endl;
  369.         Sleep(5000);
  370.         system("cls");
  371.         return user_Input();
  372.     }
  373.    
  374. }
  375.  
  376. int new_Menu(){ // NEW USER MENU
  377.     system("cls");
  378.     cout << " ----------------------------------" << endl;
  379.     cout << "|             M E N U              |" << endl;
  380.     cout << "|                                  |" << endl;
  381.     cout << "|          Select Process          |" << endl;
  382.     cout << " ----------------------------------" << endl;
  383.     cout << "[1] Deposit" << endl;
  384.     cout << "[2] Withdraw"<< endl;
  385.     cout << "[3] Balance Inquiry"<< endl;
  386.     cout << "[4] Change Pin" << endl;
  387.     cout << "[5] Validate" << endl;
  388.     cout << "[6] Logout" << endl;
  389.    
  390.     cout << "------------------------" << endl;
  391.     cout << "Choose process number: ";
  392.     cin >> x;
  393.  
  394.         if(x==1){ // DEPOSIT
  395.             system("cls");
  396.             myTrademark();
  397.             cout << "User: " << username << endl;
  398.             cout << "   ---------+ DEPOSIT +----------\n" << endl;
  399.             cout << "Balance: " << balance << endl;
  400.             cout << "\nEnter Amount to Deposit: ";
  401.             cin >> add_Bal;
  402.                 balance += add_Bal; // will add to current balance
  403.             if(add_Bal > 0 || add_Bal != 0){
  404.                 cout << "------------------------------" << endl;
  405.                 cout << "\nYour deposit is successfully transacted!\n" << endl;
  406.  
  407.                 return backtoMenu(); // return
  408.             }
  409.             else{
  410.                     cout << "\nNo Deposit has been made" << endl;
  411.                     return backtoMenu();
  412.                     new_Menu();
  413.             }
  414.         }
  415.    
  416.  
  417.         if(x==2){ // WITHDRAW
  418.             system("cls");
  419.             myTrademark();
  420.             cout << "  ---------+ WITHDRAW +----------\n" << endl;
  421.                 if(balance > 0 || balance != 0){
  422.                     cout << "Current balance: " << balance << endl;
  423.                     cout << "********************" << endl;
  424.                     cout << "\nWithdraw amount: ";
  425.                     cin >> withdraw;
  426.                         if(withdraw <= balance){
  427.                             cout << "\n[SUCCESFULLY WITHDRAWED!]" << endl;
  428.                             cout << "--------------------------------" << endl;
  429.                                 temp = balance - withdraw; // store to temporary variable in order to safely store current balance
  430.                             cout << "\nCurrent Balance " << temp << endl;
  431.                                 balance -= withdraw; // Minus to current balance
  432.                             return backtoMenu(); // return
  433.                     }
  434.                         else if(withdraw > balance){
  435.                             cout << "\nYou can't withdraw, you have insufficient funds" << endl;
  436.                             return backtoMenu(); // return
  437.                         }
  438.                 }
  439.                 else if(withdraw == 0 || withdraw < 0){
  440.                     cout << "   [YOU CAN'T WITHDRAW]" << endl;
  441.                     cout << "\nError: It seems you have insufficient enough balance.\nPlease top up." << endl;
  442.                     return backtoMenu(); // return
  443.                 }
  444.         }
  445.        
  446.         if(x==3){ // BALANCE INQUIRY
  447.             system("cls");
  448.             myTrademark();
  449.             cout << "  ------+ BALANCE INQUIRY +-------\n" << endl;
  450.                 if(add_Bal > 0 || balance != 0 || balance > 0){
  451.                     cout << "Current Balance " << balance << endl;
  452.                     return backtoMenu();
  453.                 }
  454.                 else if(add_Bal == 0){
  455.                     cout << "Your account has insufficient funds" << endl;
  456.                         while(true){
  457.                             cout << "\n============ Add Funds ============\n" << endl;
  458.                             cout << "Do you want to add funds" << endl;
  459.                             cout << "-----------------------------------\n" << endl;
  460.                             cout <<"[1] YES     [2] NO\n" << endl;
  461.                             cout << "-----------------------------------" << endl;
  462.                             cout << "Choose process number: ";
  463.                             cin >> z;
  464.  
  465.                             if(z==1){
  466.                                 cout << "Cash in amount: ";
  467.                                 cin >> cashin;
  468.  
  469.                                 cashin += balance;
  470.                                 a = cash;
  471.                                 balance = a;
  472.  
  473.                                 if(cashin > 0 || balance != 0){
  474.                                     cout << "\nYour deposit is successfully transacted!\n" << endl;
  475.                                     return backtoMenu();
  476.                                 }
  477.                             }
  478.                            
  479.                             if(z==2){
  480.                                 return new_Menu();
  481.                             }
  482.                     }
  483.                 }
  484.                 else{
  485.                     cout << "Your Balance is: " << balance << endl;
  486.                     system("pause"); // return
  487.                 }
  488.         }
  489.        
  490.         if(x==4){ // CHANGE PIN
  491.             system("cls");
  492.             myTrademark();
  493.             cout << "   --------+ CHANGE PIN +--------\n" << endl;
  494.             cout << "Enter your pin: ";
  495.                 cin >> pin_check;
  496.                 if(pin[0] != pin_check){
  497.                     cout << "Error!" << endl;
  498.             }
  499.                 if(pin[0] == pin_check){
  500.                     cout << " ----------------------------------" << endl;
  501.                     cout << "|           Changing Pin           |" << endl;
  502.                     cout << " ----------------------------------" << endl;
  503.                    
  504.                
  505.                         for(int i = 0; i < 1; i++){
  506.                             cout << "Enter pin: ";
  507.                             cin >> pin[2]; 
  508.                             for(int j = 0; j < 1; j++){
  509.                                 cout << "Enter pin again: ";
  510.                                 cin >> pin[3];
  511.                             }
  512.                         }
  513.                        
  514.                         if(pin[2] == pin[3]){
  515.                             cout << "\n[/] Pin Successfully Changed!" << endl;
  516.                             cout << "your new Pin is " << pin[2] << endl;
  517.                            
  518.                         }
  519.                         else{
  520.                             cout << "[X] Pin Doesn't Matched! please try again. " << endl;
  521.                         }
  522.                 }
  523.                
  524.                 return backtoMenu();
  525.         }
  526.            
  527.        
  528.         if(x==5){ // VALIDATE
  529.             system("cls");
  530.             myTrademark();
  531.             cout << "Account name: " << username << endl;
  532.             if(password[0] > 0){
  533.                 cout << "Password " << password[0] << endl;
  534.             }else{
  535.                 cout << "Password: NOT SET" << endl;
  536.             }
  537.             if(pin[0] > pin[2]){
  538.                 cout << "Pin: " << pin[1] << endl;
  539.             }
  540.             else{
  541.                 cout << "Pin: " << pin[2] << endl;
  542.             }
  543.             if (password1 == 0){
  544.                 cout << "\n\nYour account is weak and prone for skimming and hacking.\n";
  545.                 cout << "You wish to add password? \n";
  546.                 cout << "\n[1] YES [2] NO\n" << endl;
  547.                 cout << "=> ";
  548.                 cin >> passchoice;
  549.                
  550.                
  551.                 num5val = passchoice;
  552.                
  553.                 if(passchoice != 2){
  554.                     cout << " ----------------------------------" << endl;
  555.                     cout << "|           Add Password           |" << endl;
  556.                     cout << " ----------------------------------" << endl;
  557.                     for(int i = 0; i < 1; i++){
  558.                     cout << "=> ";
  559.                     cin >> password[0];
  560.                     cout << " ----------------------------------" << endl;
  561.                     cout << "|          Verify Password         |" << endl;
  562.                     cout << " ----------------------------------" << endl;
  563.                         for(int j = 1; j < 2; j++){
  564.                             cout << "=> ";
  565.                             cin >> password[1];
  566.                             break;
  567.                         }
  568.                 }
  569.                
  570.                 if(passchoice == 2){
  571.                     cout << "Warning! Account not validated!"<< endl;
  572.                     backtoMenu();
  573.                 }
  574.                 cout << "\nYour Account is now Validated!" << endl;
  575.                 backtoMenu();
  576.             }
  577.            
  578.         }
  579.     }
  580.        
  581.         if(x==6){ // LOGOUT
  582.             if(password[1] == 0){
  583.                 cout << "\nYou can't Logout, if you haven't validate your account." << endl;
  584.                 backtoMenu();
  585.                 new_Menu();
  586.             }
  587.             else{
  588.                 cout << "\n[Note]: Validate your account in order to get verified and Login as Registered User" << endl;
  589.                 if(num5val > 0){
  590.                 cout << "Wish to proceed?" << endl;
  591.                 system("pause");
  592.                 cout << "You can now Login as Registered User" << endl;
  593.                 system("cls");
  594.                 new_reg();
  595.             }
  596.             else if(password){
  597.                 cout << "Account not yet validated! " << endl;
  598.             }
  599.         }
  600.     }
  601. }
  602.  
  603. int main(){
  604.     user_Input();
  605. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement