Advertisement
Cnvmendoza

February 15, 2022: ATM Version 2

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