Advertisement
Cnvmendoza

February 15, 2022: ATM

Feb 14th, 2022
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.45 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. int memBalance = -1; //0 - Savings Account, 1 - Credit Account
  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.         void anotherBankTransaction(void);
  20.         //Deposit Functions
  21.         void depositBank_A1(void);
  22.         //Withdraw Functions
  23.         void withdrawBank_A1(void);
  24.         //Check Balance Functions
  25.         void checkBalance_A1(void);
  26.         //Savings or Credit Functions
  27.         void s_c_Balance(void);
  28.         //Exit Functions
  29.         void exitProgram(void);
  30.     //Tab Functions
  31.     void tab_B1(void);
  32.     void tab_B2(void);
  33.     void tab_B3(void);
  34.  
  35.  
  36. main(){
  37.     menuBank();
  38. }
  39.  
  40. //Menu Function
  41. void menuBank(void){
  42.     string input = "null";
  43.     memBalance = -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.         // Action Menu //
  57.        
  58.         // Check Balance
  59.         tab_B2();
  60.         cout << "[1] Check Balance";
  61.         cout << endl;
  62.         // Check Balance
  63.        
  64.         // Deposit
  65.         tab_B2();
  66.         cout << "[2] Deposit";
  67.         cout << endl;
  68.         // Deposit
  69.        
  70.         // Withdraw
  71.         tab_B2();
  72.         cout << "[3] Withdraw";
  73.         cout << endl;
  74.         // Withdraw
  75.        
  76.         // Exit
  77.         tab_B2();
  78.         cout << "[4] Exit";
  79.         cout << endl;
  80.         // Exit
  81.        
  82.         // Enter Input
  83.         tab_B2();
  84.         cout << "Enter Input: ";
  85.         cin >> input;
  86.     } while(!(input == "1" || input == "2" || input == "3" || input == "4"));
  87.    
  88.     if (input == "1"){
  89.         checkBalance_A1();
  90.     }
  91.     else if (input == "2"){
  92.         depositBank_A1();
  93.     }
  94.     else if (input == "3"){
  95.         withdrawBank_A1();
  96.     }
  97.     else if (input == "4"){
  98.         exitProgram();
  99.     }
  100.    
  101. }
  102. //Action Function
  103.     //Action Functions
  104.         //Deposit Functions
  105.         void depositBank_A1(void){
  106.             string input = "null";
  107.             bool validInput = false;
  108.             do {
  109.                 //Deposit Aesthetics
  110.                 tab_B1(); tab_B3();
  111.                 tab_B2();
  112.                 cout << groupName << " Bank: Deposit";
  113.                 tab_B1(); tab_B3();
  114.                 cout << endl;
  115.                 //Deposit Aesthetics
  116.                
  117.                 //Savings or Credit Account
  118.                 s_c_Balance();
  119.                 //Savings or Credit Account
  120.                
  121.                 //Enter Input
  122.                 tab_B2();
  123.                 cout << "Enter Input: ";
  124.                 cin >> input;
  125.                 //Enter Input
  126.             } while (!(input == "1" || input == "2"));
  127.            
  128.             //Balance Memory
  129.             if (input == "1"){
  130.                 memBalance = 0; // Savings Account
  131.             }
  132.             else if (input == "2"){
  133.                 memBalance = 1; // Credit Account
  134.             }
  135.             //Balance Memory
  136.            
  137.             float depositInput = 0;
  138.             do {
  139.                 //Ask Deposit
  140.                 tab_B1(); tab_B3();
  141.                 tab_B2();
  142.                 cout << "How much would you like to deposit?";
  143.                 tab_B1(); tab_B3();
  144.                 cout << endl;
  145.                 //Ask Deposit
  146.                
  147.                 //Enter Input
  148.                 tab_B2();
  149.                 cout << "Enter Amount: ";
  150.                 cin >> depositInput;
  151.                 if (!(validInput = cin.good())){
  152.                     cin.clear();
  153.                     cin.ignore(numeric_limits<streamsize>::max(), '\n');
  154.                 }
  155.                 //Enter Input
  156.             } while (depositInput < 0);
  157.            
  158.             //Deposit Output
  159.             if (memBalance == 0){
  160.                 savingsBalance += depositInput;
  161.                
  162.                 //Final Output
  163.                 tab_B2();
  164.                 cout << setprecision(2) << fixed;
  165.                 cout << currency << depositInput << " has been added to your Savings Account.";
  166.                 cout << endl;
  167.                 //Final Output
  168.                 system("pause");
  169.             }
  170.             else if (memBalance == 1){
  171.                 creditBalance += depositInput;
  172.                
  173.                 //Final Output
  174.                 tab_B2();
  175.                 cout << setprecision(2) << fixed;
  176.                 cout << currency << depositInput << " has been added to your Credit Account.";
  177.                 cout << endl;
  178.                 //Final Output
  179.                 system("pause");
  180.             }
  181.             //Deposit Output
  182.             anotherBankTransaction();
  183.         }
  184.         //Withdraw Functions
  185.         void withdrawBank_A1(void){
  186.             string input = "null";
  187.             bool validInput = false;
  188.             do {
  189.                 //Withdraw Aesthetics
  190.                 tab_B1(); tab_B3();
  191.                 tab_B2();
  192.                 cout << groupName << " Bank: Withdraw";
  193.                 tab_B1(); tab_B3();
  194.                 cout << endl;
  195.                 //Withdraw Aesthetics
  196.                
  197.                 //Savings or Credit Account
  198.                 s_c_Balance();
  199.                 //Savings or Credit Account
  200.                
  201.                 //Enter Input
  202.                 tab_B2();
  203.                 cout << "Enter Input: ";
  204.                 cin >> input;
  205.                 //Enter Input
  206.             } while (!(input == "1" || input == "2"));
  207.            
  208.             //Balance Memory
  209.             if (input == "1"){
  210.                 memBalance = 0; // Savings Account
  211.             }
  212.             else if (input == "2"){
  213.                 memBalance = 1; // Credit Account
  214.             }
  215.             //Balance Memory
  216.            
  217.             float withdrawInput = 0;
  218.             if (memBalance == 0){
  219.                 do {
  220.                     //Ask Withdraw
  221.                     tab_B1(); tab_B3();
  222.                     tab_B2();
  223.                     cout << "How much would you like to withdraw?";
  224.                     tab_B1(); tab_B3();
  225.                     cout << endl;
  226.                     //Ask Withdraw
  227.                    
  228.                     //Enter Input
  229.                     tab_B2();
  230.                     cout << "Enter Amount: ";
  231.                     cin >> withdrawInput;
  232.                     //Enter Input
  233.                     if (!(validInput = cin.good())){
  234.                         cin.clear();
  235.                         cin.ignore(numeric_limits<streamsize>::max(), '\n');
  236.                     }
  237.                 } while (withdrawInput < 0 || withdrawInput > savingsBalance);
  238.             }
  239.             else if (memBalance == 1){
  240.                 do {
  241.                     //Ask Withdraw
  242.                     tab_B1(); tab_B3();
  243.                     tab_B2();
  244.                     cout << "How much would you like to withdraw?";
  245.                     tab_B1(); tab_B3();
  246.                     cout << endl;
  247.                     //Ask Withdraw
  248.                    
  249.                     //Enter Input
  250.                     tab_B2();
  251.                     cout << "Enter Amount: ";
  252.                     cin >> withdrawInput;
  253.                     //Enter Input
  254.                     if (!(validInput = cin.good())){
  255.                         cin.clear();
  256.                         cin.ignore(numeric_limits<streamsize>::max(), '\n');
  257.                     }
  258.                 } while (withdrawInput < 0 || withdrawInput > creditBalance);
  259.             }
  260.             //Withdraw Output
  261.             if (memBalance == 0){
  262.                 savingsBalance -= withdrawInput;
  263.                
  264.                 //Final Output
  265.                 tab_B2();
  266.                 cout << setprecision(2) << fixed;
  267.                 cout << currency << withdrawInput << " has been reduced from your Savings Account.";
  268.                 cout << endl;
  269.                 //Final Output
  270.                 system("pause");
  271.             }
  272.             else if (memBalance == 1){
  273.                 creditBalance -= withdrawInput;
  274.                
  275.                 //Final Output
  276.                 tab_B2();
  277.                 cout << setprecision(2) << fixed;
  278.                 cout << currency << withdrawInput << " has been reduced from your Credit Account.";
  279.                 cout << endl;
  280.                 //Final Output
  281.                 system("pause");
  282.             }
  283.             //Withdraw Output
  284.             anotherBankTransaction();
  285.         }
  286.         //Check Balance Functions
  287.         void checkBalance_A1(void){
  288.             string input;
  289.             do {
  290.                 //Check Balance Aesthetics
  291.                 tab_B1(); tab_B3();
  292.                 tab_B2();
  293.                 cout << groupName << " Bank: Check Balance";
  294.                 tab_B1(); tab_B3();
  295.                 cout << endl;
  296.                 //Check Balance Aesthetics
  297.                
  298.                 //Savings or Credit Balance?
  299.                 s_c_Balance();
  300.                
  301.                 //Enter Input
  302.                 tab_B2();
  303.                 cout << "Enter Input: ";
  304.                 cin >> input;
  305.                 //Enter Input
  306.             } while (!(input == "1" || input == "2" || input == "3" || input == "4"));
  307.             if (input == "1"){
  308.                 //Savings Balance
  309.                 tab_B2();
  310.                 cout << setprecision(2) << fixed;
  311.                 cout << "Your savings balance: " << currency << savingsBalance;
  312.                 cout << endl;
  313.                 system("pause");
  314.                 //Savings Balance
  315.                 anotherBankTransaction();
  316.             }
  317.             if (input == "2"){
  318.                 //Credit Balance
  319.                 tab_B2();
  320.                 cout << setprecision(2) << fixed;
  321.                 cout << "Your credit balance: " << currency << creditBalance;
  322.                 cout << endl;
  323.                 system("pause");
  324.                 //Credit Balance
  325.                 anotherBankTransaction();
  326.             }
  327.         }
  328.         //Savings or Credit Function
  329.         void s_c_Balance(void){
  330.             //Savings Account
  331.             tab_B2();
  332.             cout << "[1] Savings Account";
  333.             cout << endl;
  334.             //Savings Account
  335.            
  336.             //Credit Account
  337.             tab_B2();
  338.             cout << "[2] Credit Account";
  339.             cout << endl;
  340.             //Credit Account
  341.         }
  342.         //Exit Functions
  343.         void anotherBankTransaction(void){
  344.             string input;
  345.             do {
  346.                 //Ask Transaction
  347.                 tab_B2();
  348.                 cout << "Do you want another transaction? (1 - Yes/2 - No)";
  349.                 cout << endl;
  350.                 //Ask Transaction
  351.                
  352.                 //Enter Input
  353.                 tab_B2();
  354.                 cout << "Enter Input: ";
  355.                 cin >> input;
  356.                 //Enter Input
  357.             } while (!(input == "1" || input == "2"));
  358.            
  359.             if (input == "1"){
  360.                 menuBank();
  361.             }
  362.             else if (input == "2"){
  363.                 exitProgram();
  364.             }
  365.         }
  366.         void exitProgram(void){
  367.             cout << endl;
  368.             cout << endl;
  369.             tab_B2();
  370.             cout << "Ending program . . . ";
  371.             cout << endl;
  372.             cout << endl;
  373.             abort();
  374.         }
  375. //Tabs Function
  376. void tab_B1(void){
  377.     cout << endl;
  378.     for (int a = 0; a <= 15; a++){
  379.         cout << " ";
  380.     }
  381. }
  382. void tab_B2(void){
  383.     cout << endl;
  384.     for (int a = 0; a <= 17; a++){
  385.         cout << " ";
  386.     }
  387. }
  388. void tab_B3(void){
  389.     for (int a = 0; a <= 30; a++){
  390.         cout << "=";
  391.     }
  392. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement