Advertisement
Cnvmendoza

Carl's Bank

Nov 13th, 2021 (edited)
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <limits>
  4. using namespace std;
  5. //Global Variables
  6. //Global string arrays
  7. string USERNAME[9999] = { "Doodle", "Kinchi", "Multi" }; //starting usernames
  8. string PASSWORD[9999] = { "54476", "12345", "Airplane" }; // starting passwords
  9. //Global float balance
  10. float balance[9999] = {5000, 4000, 3000}; //starting respective balance
  11. //Global user number (for arrays)
  12. int userNo;
  13. int userMemory = 3; //start at fourth term
  14.  
  15. //Prototype Variables
  16. //Account Functions
  17. bool login(void);
  18. void registerAccount(void);
  19. //Action
  20. float withdraw(void);
  21. float deposit(void);
  22. void check(void);
  23. void cancel(void);
  24. void exitProgram(void);
  25. //Tab
  26. void tab(void);
  27. void tab2(void);
  28. void tab3(void);
  29.  
  30. main(){
  31.     bool exit = false;
  32.     tab();tab3();
  33.     tab2();cout << "Welcome to Carl's Bank";
  34.     tab();tab3();
  35.     cout << endl;
  36.     while (exit != true){
  37.         string input;
  38.         do {
  39.             tab();tab3();
  40.             tab2();cout << "Carl's Bank: Home Menu";
  41.             tab();tab3();
  42.             cout << endl;
  43.             tab2();
  44.             cout << "[1] Login";
  45.             cout << endl;
  46.             cout << endl;
  47.             tab2();
  48.             cout << "[2] Register";
  49.             cout << endl;
  50.             cout << endl;
  51.             tab2();
  52.             cout << "[3] Exit";
  53.             cout << endl;
  54.             cout << endl;
  55.             cout << endl;
  56.             tab2();
  57.             cout << "Input: ";
  58.             cin >> input;
  59.         } while (!(input == "1" || input == "2" || input == "3"));
  60.         if (input == "1"){
  61.             bool valid = login();
  62.             if (valid){
  63.                 tab2();
  64.                 cout << "Greetings, " << USERNAME[userNo];
  65.                 bool cancel = false;
  66.                 while (!(cancel)){
  67.                     string input2;
  68.                     do {
  69.                         cout << endl;
  70.                         tab();tab3();
  71.                         tab2();
  72.                         cout << "Carl's Bank: Action";
  73.                         tab();tab3();
  74.                         cout << endl;
  75.                         tab2();
  76.                         cout << "[1] Deposit Money";
  77.                         cout << endl;
  78.                         cout << endl;
  79.                         tab2();
  80.                         cout << "[2] Withdraw Money";
  81.                         cout << endl;
  82.                         cout << endl;
  83.                         tab2();
  84.                         cout << "[3] Check Balance";
  85.                         cout << endl;
  86.                         cout << endl;
  87.                         tab2();
  88.                         cout << "[4] Log out";
  89.                         cout << endl;
  90.                         cout << endl;
  91.                         cout << endl;
  92.                         tab2();
  93.                         cout << "Input: ";
  94.                         cin >> input2;
  95.                     } while (!(input2 == "1" || input2 == "2" || input2 == "3" || input2 == "4"));
  96.                     if (input2 == "1"){
  97.                         balance[userNo] += deposit();
  98.                     }
  99.                     else if (input2 == "2"){
  100.                         balance[userNo] -= withdraw();
  101.                     }
  102.                     else if (input2 == "3"){
  103.                         check();
  104.                     }
  105.                     else if (input2 == "4"){
  106.                         cancel = true;
  107.                     }
  108.                 }
  109.             }
  110.         }
  111.         else if (input == "2"){
  112.             registerAccount();
  113.         }
  114.         else if (input == "3"){
  115.             exitProgram();
  116.         }
  117.     }
  118. }
  119.  
  120. //login function
  121. bool login(void){
  122.     string username;
  123.     string password;
  124.     cout << endl;
  125.     cout << endl;
  126.     tab();tab3();
  127.     tab2();
  128.     cout << "Carl's Bank: Login";
  129.     tab();tab3();
  130.     cout << endl;
  131.     tab2();
  132.     cout << "Enter Username: ";
  133.     cin >> username;
  134.     cout << endl;
  135.     tab2();
  136.     cout << "Enter Password: ";
  137.     cin >> password;
  138.     cout << endl;
  139.    
  140.     for (int i = 0; i < 100; i++){
  141.         if ((username.compare(USERNAME[i]) == 0) &&
  142.             (password.compare(PASSWORD[i]) == 0)){
  143.                 userNo = i;
  144.                 return true;
  145.         }
  146.     }
  147.     return false;
  148. }
  149.  
  150. float withdraw(void){
  151.     float x;
  152.     bool validInput = false;
  153.     x = -1;
  154.     cout << endl;
  155.     do {
  156.         cout << endl;
  157.         tab2();
  158.         cout << "How much do you want to withdraw? ";
  159.         cin >> x;
  160.         if (!(validInput = cin.good())){
  161.             cin.clear();
  162.             cin.ignore(numeric_limits<streamsize>::max(), '\n');
  163.         }
  164.     } while (!(x >= 0 && x <= balance[userNo]));
  165.     cout << endl;
  166.     tab2();
  167.     cout << setprecision(2) << fixed;
  168.     cout << "Php " << x << " has been reduced from your account . . . ";
  169.     cout << endl;
  170.     system("pause");
  171.     return x;
  172. }
  173.  
  174. float deposit(void){
  175.     float x;
  176.     bool validInput = false;
  177.     cout << endl;
  178.     do {
  179.         cout << endl;
  180.         tab2();
  181.         cout << "How much do you want to deposit? ";
  182.         cin >> x;
  183.         if (!(validInput = cin.good())){
  184.             cin.clear();
  185.             cin.ignore(numeric_limits<streamsize>::max(), '\n');
  186.         }
  187.     } while (!(x >= 0) && !validInput);
  188.     cout << endl;
  189.     tab2();
  190.     cout << setprecision(2) << fixed;
  191.     cout << "Php " << x << " has been added to your account . . . ";
  192.     cout << endl;
  193.     system("pause");
  194.     return x;
  195. }
  196.  
  197. void check(void){
  198.     cout << endl;
  199.     cout << endl;
  200.     tab2();
  201.     cout << setprecision(2) << fixed;
  202.     cout << "Your balance: Php " << balance[userNo];
  203.     cout << endl;
  204.     system("pause");
  205. }
  206.  
  207. void tab(void){
  208.     cout << endl;
  209.     for (int a = 0; a <= 15; a++){
  210.         cout << " ";
  211.     }
  212. }
  213.  
  214. void tab2(void){
  215.     for (int a = 0; a <= 17; a++){
  216.         cout << " ";
  217.     }
  218. }
  219.  
  220. void tab3(void){
  221.     for (int a = 0; a <= 30; a++){
  222.         cout << "=";
  223.     }
  224.     cout << endl;
  225. }
  226.  
  227. void registerAccount(void){
  228.     string input, input2;
  229.     float input3;
  230.     int b = 0, c, d;
  231.     tab();tab3();
  232.     tab2();
  233.     cout << "Carl's Bank: Register";
  234.     tab();tab3();
  235.     cout << endl;
  236.     do {
  237.         d = 0;
  238.         tab2();
  239.         cout << "Enter Username: "; cin >> input;
  240.         cout << endl;
  241.         cout << endl;
  242.         for (c = 0; c <= userMemory-1; c++){
  243.             if (input == USERNAME[c]){
  244.                 d = 1;
  245.             }
  246.             if (d == 1){
  247.                 b = 0;
  248.             }
  249.             else b = 1;
  250.         }
  251.         if (b == 0){
  252.             tab2();
  253.             cout << "This username has already been used . . . ";
  254.             cout << endl;
  255.             cout << endl;
  256.             system("pause");
  257.         }
  258.     } while(b == 0);
  259.     tab2();
  260.     cout << "Enter Password: "; cin >> input2;
  261.     cout << endl;
  262.     cout << endl;  
  263.     bool validInput = false;
  264.     do {
  265.         tab2();
  266.         cout << "Deposit Balance: "; cin >> input3;
  267.         cout << endl;
  268.         if (!(validInput = cin.good())){
  269.             cin.clear();
  270.             cin.ignore(numeric_limits<streamsize>::max(), '\n');
  271.         }
  272.     } while (input3 <= 0 && !validInput);
  273.     USERNAME[userMemory] = input;
  274.     PASSWORD[userMemory] = input2;
  275.     balance[userMemory] = input3;
  276.     userMemory++;
  277. }
  278.  
  279. void exitProgram(void){
  280.     cout << endl;
  281.     cout << endl;
  282.     tab2();
  283.     cout << "Ending program . . . ";
  284.     cout << endl;
  285.     cout << endl;
  286.     abort();
  287. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement