Cnvmendoza

ATM Datatype Function Test

Jan 17th, 2022 (edited)
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.29 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 = "Carl'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 = "inputMenu";
  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.                 savingsBalance += inputBankAction;
  194.                
  195.                 //Final Output
  196.                 tab_B2();
  197.                 cout << setprecision(2) << fixed;
  198.                 cout << currency << inputBankAction << actionBankString3[actionBank2] << " your Savings Account.";
  199.                 cout << endl;
  200.                 //Final Output
  201.                 system("pause");
  202.             }
  203.             else if (memBalance == 1){
  204.                 if (actionBank2 == 0) creditBalance += inputBankAction;
  205.                 else if (actionBank2 == 1) creditBalance -= inputBankAction;
  206.                
  207.                 //Final Output
  208.                 tab_B2();
  209.                 cout << setprecision(2) << fixed;
  210.                 cout << currency << inputBankAction << actionBankString3[actionBank2] << " your Credit Account.";
  211.                 cout << endl;
  212.                 //Final Output
  213.                 system("pause");
  214.             }
  215.             exitBank = anotherBankTransaction();
  216.         }
  217.         //Savings or Credit Function
  218.         int s_c_Balance(int mem){
  219.             bool validInput = false;
  220.             mem = -1;
  221.             do {
  222.                 //Savings Account
  223.                 tab_B2();
  224.                 cout << "[1] Savings Account";
  225.                 cout << endl;
  226.                 //Savings Account
  227.                
  228.                 //Credit Account
  229.                 tab_B2();
  230.                 cout << "[2] Credit Account";
  231.                 cout << endl;
  232.                 //Credit Account
  233.                
  234.                 //Enter Input
  235.                 tab_B2();
  236.                 cout << "Enter Input: ";
  237.                 cin >> mem;
  238.                 if (!(validInput = cin.good())){
  239.                     cin.clear();
  240.                     cin.ignore(numeric_limits<streamsize>::max(), '\n');
  241.                 }
  242.                 //Enter Input
  243.             } while (!(mem == 1 || mem == 2));
  244.             return mem-1;
  245.         }
  246.         //Exit Functions
  247.         bool anotherBankTransaction(void){
  248.             int input;
  249.             bool validInput = false;
  250.             bool exitBankTransaction = false;
  251.             do {
  252.                 //Ask Transaction
  253.                 tab_B2();
  254.                 cout << "Do you want another transaction? (1 - Yes/2 - No)";
  255.                 cout << endl;
  256.                 //Ask Transaction
  257.                
  258.                 //Enter Input
  259.                 tab_B2();
  260.                 cout << "Enter Input: ";
  261.                 cin >> input;
  262.                 if (!(validInput = cin.good())){
  263.                     cin.clear();
  264.                     cin.ignore(numeric_limits<streamsize>::max(), '\n');
  265.                 }
  266.                 input--;
  267.                 //Enter Input
  268.             } while (!(input == 0 || input == 1));
  269.             if (input == 1){
  270.                 exitBankTransaction = exitProgram();
  271.                 return exitBankTransaction;
  272.             }
  273.         }
  274.         bool exitProgram(void){
  275.             cout << endl;
  276.             cout << endl;
  277.             tab_B2();
  278.             cout << "Ending program . . . ";
  279.             cout << endl;
  280.             cout << endl;
  281.             return true;
  282.         }
  283. //Tabs Function
  284. void tab_B1(void){
  285.     cout << endl;
  286.     for (int a = 0; a <= 15; a++){
  287.         cout << " ";
  288.     }
  289. }
  290. void tab_B2(void){
  291.     cout << endl;
  292.     for (int a = 0; a <= 17; a++){
  293.         cout << " ";
  294.     }
  295. }
  296. void tab_B3(void){
  297.     for (int a = 0; a <= 30; a++){
  298.         cout << "=";
  299.     }
  300. }
Add Comment
Please, Sign In to add comment