Advertisement
homer512

someone likes gotos

Mar 19th, 2014
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctype.h>
  3. #include <stdio.h>
  4. #include <ios>
  5. #include <ostream>
  6.  
  7. using namespace std;
  8.  
  9. template <typename data, typename result>
  10.     bool check (data evaluate, result &value) {
  11.         cout << "Is " << evaluate << " correct?  Type 'Yes' or 'No'." << endl;
  12.         CHECKING:
  13.         string response = "Y";
  14. //      getline (cin, response);
  15.         if ((response == "YES") || (response == "Y")) {
  16.             value = false;
  17.         }
  18.         else if ((response == "NO") || (response == "N")) {
  19.             value = true;
  20.         }
  21.         else {
  22.             cout << "You didn't give a proper response... type either a Y or Yes for " << evaluate << " being correct, or a N or No for it being incorrect." << endl;
  23.             goto CHECKING;
  24.         }
  25.     }
  26.  
  27. class BankAccount {
  28.     public:
  29.    
  30.     int balance;
  31.     string owner;
  32.    
  33.     void get_value () {
  34.         bool boolean = true;
  35.         do {
  36.             cout << "Who owns this Bank Account?\n";
  37. //          getline (cin, owner);
  38.             owner = "Harry";
  39.             check (owner, boolean);
  40.         } while (boolean);
  41.         boolean = true;
  42.         do {
  43.             cout << "How much money does " << owner << " have in their account?\n";
  44. //          cin >> balance;
  45.             balance = 2342135215;
  46.             check (balance, boolean);
  47.         } while (boolean);
  48.         cout << "Excellent.\n";
  49.     }
  50.    
  51.     int change_value () {
  52.         cout << "Are you withdrawing (W) or depositing (D) today?" << endl;
  53.         CHANGE:
  54.         bool boolean = true;
  55.         string selection;
  56.         int amount;
  57. //      getline (cin, selection);
  58.         selection = "D";
  59.         if ((selection == "D") || (selection == "DEPOSIT")) {
  60.           do {
  61.             cout << "How much are you depositing?" << endl;
  62. //          cin >> amount;
  63.             amount = 342;
  64.             check (amount, boolean);
  65.           } while (boolean);
  66.           balance = balance + amount;
  67.         }
  68.         else if ((selection == "W") || (selection == "WITHDRAW")) {
  69.           WITHDRAW:
  70.           boolean = true;
  71.           do {
  72.             cout << "How much are you withdrawing?" << endl;
  73. //          cin >> amount;
  74.             amount = 234;
  75.             check (amount, boolean);
  76.           } while (boolean);
  77.           balance = balance - amount;
  78.           if (balance < 0) {
  79.             balance = balance + amount;
  80.             cout << "Oops, you tried withdrawing more than what was in your account!  Try again... Your balance is " << balance << "." << endl;
  81.             goto WITHDRAW;
  82.           }
  83.         }
  84.         else if ((selection == "C") || (selection == "CANCEL")) {
  85.             boolean = true;
  86.             check (selection, boolean);
  87.             if (boolean == true) {
  88.                 goto DONE;
  89.             }
  90.             goto CHANGE;
  91.         }
  92.         else {
  93.           cout << "You didn't make a viable selection.. you need to type either a W to withdraw or a D to deposit.  If you would like to cancel this transaction, type C." << endl;
  94.           goto CHANGE;
  95.         }
  96.         DONE:
  97.     return 0;
  98.     }
  99. };
  100.  
  101. int main () {
  102.     BankAccount First;
  103.     First.get_value ();
  104.     First.change_value ();
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement