Cnvmendoza

February 16, 2022: ATM Version 3

Feb 16th, 2022 (edited)
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <limits>
  4. using namespace std;
  5.  
  6. //Global Variables
  7. //PIN Arrays
  8. int PIN[] = { 1111, 2222, 3333, 4444 };
  9. int ID = -1;
  10. //Balance Variables
  11. float savingsBalance[] = { 100, 200, 300, 400 };
  12. float creditBalance[] = { 10, 20, 30, 40 };
  13. //Memory Variable
  14. bool exitBank = false;
  15. bool exitPIN = false;
  16. //Name String Variable
  17. string groupName = "Test's ";
  18. string currency = "Php ";
  19. //Prototype Functions
  20.     //Menu Function
  21.     //void menuBank(void);
  22.     //Action Functions
  23.         bool anotherBankTransaction(void);
  24.         //Deposit Functions
  25.         void actionBank(int memBalance, int actionBank2);
  26.         //Savings or Credit Functions
  27.         int s_c_Balance(int mem);
  28.         //Exit Functions
  29.         bool exitProgram(void);
  30.     //Tab Functions
  31.     void tab_B1(void);
  32.     void tab_B2(void);
  33.     void tab_B3(void);
  34.  
  35. main(){
  36.     int PIN2 = -1;
  37.     bool exitPIN2 = false;
  38.     bool validInputPIN = false;
  39.     while (exitPIN != true){
  40.         exitPIN = false;
  41.         exitPIN2 = false;
  42.         exitBank = false;
  43.         ID = -1;
  44.         do {
  45.             // Welcome //
  46.             tab_B1(); tab_B3();
  47.            
  48.             tab_B2();
  49.             cout << "Welcome to " << groupName << " Bank!";
  50.            
  51.             tab_B1(); tab_B3();
  52.            
  53.             cout << endl;
  54.             // Welcome //
  55.            
  56.             // Enter PIN //
  57.             tab_B2();
  58.             cout << "Enter PIN: ";
  59.             cin >> PIN2;
  60.             if (!(validInputPIN = cin.good())){
  61.                 cin.clear();
  62.                 cin.ignore(numeric_limits<streamsize>::max(), '\n');
  63.             }
  64.             // Enter PIN //
  65.             for (int verify = 0; verify <= 3; verify++){
  66.                 if (PIN2 == PIN[verify]){
  67.                     ID = verify;
  68.                     exitPIN2 = true;
  69.                 }
  70.             }
  71.         } while (exitPIN2 != true);
  72.         while (exitBank != true){
  73.             string inputMenu = "null";
  74.             int memBalance = -1; //0 - Savings Account, 1 - Credit Account
  75.             int actionBank2 = -1; // 0 - Deposit, 1 - Withdraw
  76.             do {
  77.                 // Welcome //
  78.                 tab_B1(); tab_B3();
  79.                
  80.                 tab_B2();
  81.                 cout << "Welcome to " << groupName << " Bank!";
  82.                
  83.                 tab_B1(); tab_B3();
  84.                
  85.                 cout << endl;
  86.                 // Welcome //
  87.                
  88.                 // Action Menu //
  89.                
  90.                 // Check Balance
  91.                 tab_B2();
  92.                 cout << "[1] Check Balance";
  93.                 cout << endl;
  94.                 // Check Balance
  95.                
  96.                 // Deposit
  97.                 tab_B2();
  98.                 cout << "[2] Deposit";
  99.                 cout << endl;
  100.                 // Deposit
  101.                
  102.                 // Withdraw
  103.                 tab_B2();
  104.                 cout << "[3] Withdraw";
  105.                 cout << endl;
  106.                 // Withdraw
  107.                
  108.                 // Logout
  109.                 tab_B2();
  110.                 cout << "[4] Log Out";
  111.                 cout << endl;
  112.                 // Logout
  113.                
  114.                 // Exit
  115.                 tab_B2();
  116.                 cout << "[5] Exit";
  117.                 cout << endl;
  118.                 // Exit
  119.                
  120.                 // Enter Input
  121.                 tab_B2();
  122.                 cout << "Enter Input: ";
  123.                 cin >> inputMenu;
  124.             } while(!(inputMenu == "1" || inputMenu == "2" || inputMenu == "3" || inputMenu == "4" || inputMenu == "5")); // do while
  125.             if (inputMenu == "1"){ // Check Balance
  126.                 do {
  127.                     //Check Balance Aesthetics
  128.                     tab_B1(); tab_B3();
  129.                     tab_B2();
  130.                     cout << groupName << " Bank: Check Balance";
  131.                     tab_B1(); tab_B3();
  132.                     cout << endl;
  133.                     //Check Balance Aesthetics
  134.                    
  135.                     //Savings or Credit Balance?
  136.                     memBalance = s_c_Balance(memBalance);
  137.                 } while (!(memBalance == 0 || memBalance == 1)); // Check Balance
  138.                 if (memBalance == 0){
  139.                     //Savings Balance
  140.                     tab_B2();
  141.                     cout << setprecision(2) << fixed;
  142.                     cout << "Your savings balance: " << currency << savingsBalance[ID];
  143.                     cout << endl;
  144.                     system("pause");
  145.                     //Savings Balance
  146.                     exitBank = anotherBankTransaction();
  147.                 } //if
  148.                 if (memBalance == 1){
  149.                     //Credit Balance
  150.                     tab_B2();
  151.                     cout << setprecision(2) << fixed;
  152.                     cout << "Your credit balance: " << currency << creditBalance[ID];
  153.                     cout << endl;
  154.                     system("pause");
  155.                     //Credit Balance
  156.                     exitBank = anotherBankTransaction();
  157.                 } //if
  158.             } // Check Balance
  159.             else if (inputMenu == "2"){ //Deposit
  160.                 actionBank2 = 0;
  161.                 actionBank(memBalance, actionBank2);
  162.             } // Deposit
  163.             else if (inputMenu == "3"){ //Withdraw
  164.                 actionBank2 = 1;
  165.                 actionBank(memBalance, actionBank2);
  166.             }
  167.             else if (inputMenu == "4"){
  168.                 exitBank = true;
  169.             }
  170.             else if (inputMenu == "5"){
  171.                 exitBank = exitProgram();
  172.                 exitPIN = true;
  173.             }
  174.         } //while loop
  175.     }
  176. }
  177. //Action Function
  178.     //Action Functions
  179.         //Deposit Functions
  180.         void actionBank(int memBalance, int actionBank2){
  181.             //actionBank2 0 - Deposit, 1 - Withdraw
  182.             bool validInput = false;
  183.             string actionBankString[] = { "Deposit", "Withdraw" };
  184.             string actionBankString2[] = { "deposit", "withdraw" };
  185.             string actionBankString3[] = { " has been added to", " has been reduced from" };
  186.             do {
  187.                 //Deposit/Withdraw Aesthetics
  188.                 tab_B1(); tab_B3();
  189.                 tab_B2();
  190.                 cout << groupName << " Bank: " << actionBankString[actionBank2];
  191.                 tab_B1(); tab_B3();
  192.                 cout << endl;
  193.                 //Deposit/Withdraw Aesthetics
  194.                
  195.                 //Savings or Credit Account
  196.                 memBalance = s_c_Balance(memBalance);
  197.                 //Savings or Credit Account
  198.             } while (!(memBalance == 0 || memBalance == 1));
  199.             float inputBankAction = -1;
  200.             //Ask Deposit/Withdraw
  201.             tab_B1(); tab_B3();
  202.             tab_B2();
  203.             cout << "How much would you like to " << actionBankString2[actionBank2] << "?";
  204.             tab_B1(); tab_B3();
  205.             cout << endl;
  206.             //Ask Deposit/Withdraw
  207.             float balance = -1;
  208.             if (memBalance == 0){
  209.                 balance = savingsBalance[ID];
  210.             }
  211.             else if (memBalance == 1){
  212.                 balance = creditBalance[ID];
  213.             }
  214.            
  215.             if (actionBank2 == 0){
  216.                 do {
  217.                     //Enter Input
  218.                     tab_B2();
  219.                     cout << "Enter Amount: ";
  220.                     cin >> inputBankAction;
  221.                     if (!(validInput = cin.good())){
  222.                         cin.clear();
  223.                         cin.ignore(numeric_limits<streamsize>::max(), '\n');
  224.                     }
  225.                     //Enter Input
  226.                 } while (inputBankAction < 0);
  227.             }
  228.             else if (actionBank2 == 1){
  229.                 do {
  230.                     //Enter Input
  231.                     tab_B2();
  232.                     cout << "Enter Amount: ";
  233.                     cin >> inputBankAction;
  234.                     if (!(validInput = cin.good())){
  235.                         cin.clear();
  236.                         cin.ignore(numeric_limits<streamsize>::max(), '\n');
  237.                     }
  238.                     //Enter Input
  239.                 } while (inputBankAction < 0 || inputBankAction > balance);
  240.             }
  241.            
  242.             //Deposit/Withdraw Output
  243.             if (memBalance == 0){
  244.                 if (actionBank2 == 0) savingsBalance[ID] += inputBankAction;
  245.                 else if (actionBank2 == 1) savingsBalance[ID] -= inputBankAction;
  246.                
  247.                 //Final Output
  248.                 tab_B2();
  249.                 cout << setprecision(2) << fixed;
  250.                 cout << currency << inputBankAction << actionBankString3[actionBank2] << " your Savings Account.";
  251.                 cout << endl;
  252.                 //Final Output
  253.                 system("pause");
  254.             }
  255.             else if (memBalance == 1){
  256.                 if (actionBank2 == 0) creditBalance[ID] += inputBankAction;
  257.                 else if (actionBank2 == 1) creditBalance[ID] -= inputBankAction;
  258.                
  259.                 //Final Output
  260.                 tab_B2();
  261.                 cout << setprecision(2) << fixed;
  262.                 cout << currency << inputBankAction << actionBankString3[actionBank2] << " your Credit Account.";
  263.                 cout << endl;
  264.                 //Final Output
  265.                 system("pause");
  266.             }
  267.             exitBank = anotherBankTransaction();
  268.         }
  269.         //Savings or Credit Function
  270.         int s_c_Balance(int mem){
  271.             bool validInput = false;
  272.             mem = -1;
  273.             do {
  274.                 //Savings Account
  275.                 tab_B2();
  276.                 cout << "[1] Savings Account";
  277.                 cout << endl;
  278.                 //Savings Account
  279.                
  280.                 //Credit Account
  281.                 tab_B2();
  282.                 cout << "[2] Credit Account";
  283.                 cout << endl;
  284.                 //Credit Account
  285.                
  286.                 //Enter Input
  287.                 tab_B2();
  288.                 cout << "Enter Input: ";
  289.                 cin >> mem;
  290.                 if (!(validInput = cin.good())){
  291.                     cin.clear();
  292.                     cin.ignore(numeric_limits<streamsize>::max(), '\n');
  293.                 }
  294.                 //Enter Input
  295.             } while (!(mem == 1 || mem == 2));
  296.             return mem-1;
  297.         }
  298.         //Exit Functions
  299.         bool anotherBankTransaction(void){
  300.             int input;
  301.             bool validInput = false;
  302.             bool exitBankTransaction = false;
  303.             do {
  304.                 //Ask Transaction
  305.                 tab_B2();
  306.                 cout << "Do you want another transaction? (1 - Yes/2 - No)";
  307.                 cout << endl;
  308.                 //Ask Transaction
  309.                
  310.                 //Enter Input
  311.                 tab_B2();
  312.                 cout << "Enter Input: ";
  313.                 cin >> input;
  314.                 if (!(validInput = cin.good())){
  315.                     cin.clear();
  316.                     cin.ignore(numeric_limits<streamsize>::max(), '\n');
  317.                 }
  318.                 input--;
  319.                 //Enter Input
  320.             } while (!(input == 0 || input == 1));
  321.             if (input == 1){
  322.                 exitBankTransaction = exitProgram();
  323.                 exitPIN = true;
  324.                 return exitBankTransaction;
  325.             }
  326.         }
  327.         bool exitProgram(void){
  328.             cout << endl;
  329.             cout << endl;
  330.             tab_B2();
  331.             cout << "Ending program . . . ";
  332.             cout << endl;
  333.             cout << endl;
  334.             return true;
  335.         }
  336. //Tabs Function
  337. void tab_B1(void){
  338.     cout << endl;
  339.     for (int a = 0; a <= 15; a++){
  340.         cout << " ";
  341.     }
  342. }
  343. void tab_B2(void){
  344.     cout << endl;
  345.     for (int a = 0; a <= 17; a++){
  346.         cout << " ";
  347.     }
  348. }
  349. void tab_B3(void){
  350.     for (int a = 0; a <= 30; a++){
  351.         cout << "=";
  352.     }
  353. }
Add Comment
Please, Sign In to add comment