Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.94 KB | None | 0 0
  1. //using std with cout and cin instead of namespace
  2.  
  3. #include <iostream>
  4. #include <string>
  5. #include <ctime>
  6. #include <conio.h>
  7. #include <stdio.h>
  8.  
  9. struct User {
  10.     int acctNumber1;            //User account number 1
  11.     int acctNumber2;
  12.     double acctBalance1;        //user account balance 1
  13.     double acctBalance2;       
  14.     int acctInterest1;          //user account interest rate1
  15.     int acctInterest2;
  16.     char acctName[256];         //User account Name
  17.     char acctPass[256];         //user account password
  18.     int logInNumber;
  19.     bool isAdmin;
  20. } account[8999]; // 9999 - 1000 because we virtually start at record '1000'
  21.  
  22. void printSummary(int user) {
  23.     printf("\n\n"
  24.            "+-----------------+\n"
  25.            "| Account Summary |\n"
  26.            "+=================+\n\n"
  27.            "+-----------------------------------------------------+\n"
  28.            "| Account | Account number | Balance  | Interest Rate |\n"
  29.            "+---------+----------------+--------------------------+\n"
  30.            "| 1       | %d           | %.2lf                      \n"           //add interest rate 1 and 2
  31.            "| 2       | %d           | %.2lf                      \n\n\n",
  32.            account[user].acctNumber1, account[user].acctBalance1, account[user].acctNumber2, account[user].acctBalance2);
  33. }
  34.  
  35. void createAccount(int *n) {
  36.     *n = *n+1;
  37.     int *inputInt = new int[1];
  38.     std::cout << "Please Fill out the following information to create a new account" << std::endl;
  39.     std::cout << "Full name: ";
  40.     std::cin >> account[*n].acctName;
  41.     std::cout << "Password: ";
  42.     std::cin >> account[*n].acctPass;
  43.                
  44.     // get first account number
  45.     std::cout << "First account number: ";
  46.     std::cin >> *inputInt;
  47.     while(*inputInt < 1000 || *inputInt > 9999) { // check none of the users already have this account number, if they do keep prompting
  48.         std::cout   << "Account number invalid. Must be between 1000 and 9999.\n"
  49.                     << "------------------------------------------------------\n"
  50.                     << "First account number: ";                   
  51.         std::cin >> *inputInt;
  52.     }
  53.     account[*n].acctNumber1 = *inputInt; // valid (new) account number, add it to the user
  54.  
  55.     // get first account balance
  56.     std::cout << "First account Balance: ";
  57.     std::cin >> account[*n].acctBalance1;
  58.  
  59.     //check its between 0 and 100,000 else re ask
  60.  
  61.     //get first interest rate, check its between .01% and 15% else re ask
  62.  
  63.     // get second account number
  64.     std::cout << "Second account number: ";
  65.     std::cin >> *inputInt;
  66.     while(*inputInt < 1000 || *inputInt > 8999) { // check none of the users already have this account number, if they do keep prompting
  67.         std::cout   << "Account number invalid. Must be between 1000 and 9999.\n"
  68.                     << "------------------------------------------------------\n"
  69.                     << "Second account number: ";
  70.         std::cin >> *inputInt;
  71.     }
  72.     account[*n].acctNumber2 = *inputInt; // valid (new) account number, add it to the user
  73.  
  74.     //get second account balance
  75.     std::cout << "Second account balance: ";
  76.     std::cin >> account[*n].acctBalance2;
  77.  
  78.     //check its between 0 and 100,000 else re ask
  79.  
  80.     //get first interest rate, check its between .01% and 15% else re ask
  81.    
  82. }
  83.  
  84. void login(int *userId, int *loggedIn) {
  85.     char *inputText = new char[256];
  86.     std::cout << "Please enter username: ";
  87.     std::cin >> inputText;
  88.     for(int i = 0; i < 8999; i++) {
  89.         if ( strcmp (account[i].acctName, inputText) == 0 ) {
  90.             std::cout << "Welcome " << account[i].acctName << ", Please enter your password: " << std::endl; //move to logged in menu
  91.             std::cin >> inputText;
  92.             if ( strcmp (account[i].acctPass, inputText) == 0 ) {
  93.                 printSummary(i);
  94.                 std::cout << "Press [Enter] to continue" << std::endl;
  95.                 _getch();
  96.                 *loggedIn = 1;
  97.                 account[i].logInNumber++;
  98.                 *userId = i;
  99.             }
  100.             else {
  101.                 std::cout << "Incorrect password." << std::endl;
  102.                 break;
  103.             }
  104.         }
  105.     }
  106. }
  107.  
  108. void transferMoney(int *userId) {
  109.     double amount = 0.00;
  110.     bool enoughFunds = false;
  111.     std::cout   << "Please enter amount to transer: ";
  112.     std::cin    >> amount;
  113.     if(account[*userId].acctNumber1 == account[*userId].acctNumber2) {
  114.         printf( "   ^       +-----------+\n"
  115.                 " / ! \\     | Declined: |  Account numbers are the same.\n"
  116.                 "/____ \\    +-----------+\n\n");
  117.     }
  118.     if(amount > account[*userId].acctBalance1) {
  119.         printf( "   ^       +-----------+\n"
  120.                 " / ! \\     | Declined: |  Not enough founds in account number %d\n"
  121.                 "/____ \\    +-----------+\n\n",
  122.                 account[*userId].acctNumber1);
  123.     } else { enoughFunds = true; }
  124.     if(enoughFunds && (account[*userId].acctBalance1 - amount) < 10.00) {
  125.         printf( "+----------+\n"
  126.                 "| Warning: |   Account number %d now has a balance less than $10.00.\n"
  127.                 "+----------+\n\n",
  128.                 account[*userId].acctNumber1);
  129.         account[*userId].acctBalance2 += amount;
  130.         account[*userId].acctBalance1 -= amount;
  131.         std::cout << "Press [Enter] to continue" << std::endl;
  132.         enoughFunds = false; //prevent a second transfer happening
  133.     }
  134.     if(enoughFunds) {
  135.         if((amount + account[*userId].acctBalance2) > 100000.00) {
  136.             printf( "+----------+\n"
  137.                     "| Warning: |   Account number %d will have a balance greater\n"
  138.                     "+----------+   than the federally insurable amount of\n"
  139.                     "               $100,000.00 if you proceed.\n\n",
  140.                     account[*userId].acctNumber2);
  141.             char yn = 'x';     
  142.             // loop until the input is a y or n
  143.             while(yn != 'y' && yn != 'n') {
  144.                 std::cout << "Continue with transfer? Select [Y]es or [N]o" << std::endl;
  145.                 std::cin >> yn;
  146.             }
  147.             if(yn = 'n') {
  148.                 exit(0);
  149.             }
  150.         } else {
  151.             // make the transfer
  152.             account[*userId].acctBalance2 += amount;
  153.             account[*userId].acctBalance1 -= amount;
  154.             printf( "\n\n\n+--------------------+"
  155.                     "| Transfer complete. |"
  156.                     "+--------------------+\n\n\n");
  157.             printSummary(*userId);
  158.         }
  159.     }
  160.     std::cout << "Press [Enter] to continue" << std::endl;
  161.     _getch();
  162. }
  163.  
  164. void saveData() {//save all user account data to a csv file
  165. //ACCTNAME, ACCTNUMBER1, ACCTBALANCE1, ACCTINTEREST1, ACCTNUMBER2, ACCTBALANCE2, ACCT INTEREST2, PASSWORD,
  166. }
  167.  
  168. void accountDeposit(int *userId) {
  169.    
  170.     int acctDepNum = 0;
  171.     int acctDepAmt = 0;
  172.  
  173.     std::cout   <<  "Please enter the account number you wish to deposit to"    <<  std::endl
  174.                 <<  "1."    <<  std::endl //user ACCTNUMBER 1
  175.                 <<  "2."    <<  std::endl //user acctnumber 2
  176.                 <<  std::endl;
  177.     std::cin    >>  acctDepNum;
  178.  
  179.     std::cout   <<  "Please enter deposit amount"   <<  std::endl;
  180.     std::cin    >>  acctDepNum;
  181.  
  182.     if (acctDepNum == 1) {
  183.         account[*userId].acctBalance1 +=    acctDepAmt;
  184.     }
  185.     if (acctDepNum == 2) {
  186.         account[*userId].acctBalance2 += acctDepAmt;
  187.     }
  188.     saveData();
  189.     return; //return to logged in menu
  190. }
  191.  
  192. void accountWithdraw(int *userId) {
  193.    
  194.     int acctWitNum = 0;
  195.     int acctWitAmt = 0;
  196.  
  197.     std::cout   <<  "Please enter the account number you wish to deposit to"<<endl
  198.                 <<  "1."<<endl //user ACCTNUMBER 1
  199.                 <<  "2."<<endl //user acctnumber 2
  200.                 <<  endl;
  201.     std::cin    >>  acctWitNum;
  202.  
  203.     std::cout   <<  "Please enter deposit amount"<<endl;
  204.     std::cin    >>  acctWitNum;
  205.  
  206.     if(acctWitNum == 1) {
  207.         account[*userId].acctBalance1 +=    acctWitAmt;
  208.     }
  209.     if(acctWitNum == 2) {
  210.         account[*userId].acctBalance2 += acctWitAmt;
  211.     }
  212.     saveData(); //run save data
  213.     return;
  214. }
  215.  
  216. void loggedInMenu(int *userId) {
  217.  
  218.     int loggedinmenuselect = 0;
  219.         while(loggedinmenuselect == 0) {    //show menu when logged in is complete.
  220.             std::cout   <<  "Hello, acctname! Welcome to your account screen, Please select from the following menu: " << endl;
  221.             std::cin    >>  loggedinmenuselect;
  222.  
  223.             //1. account summary
  224.             if(loggedinmenuselect ==1) {
  225.                 printSummary(*userId);
  226.             }
  227.             //2. initiate balance transfer
  228.             if(loggedinmenuselect ==2) {
  229.                 transferMoney(*userId);
  230.             }
  231.             //3. deposit to account
  232.             if(loggedinmenuselect ==3) {
  233.                 printSummary(*userId);
  234.             }
  235.             //4. withdraw from account
  236.             if(loggedinmenuselect ==4) {
  237.                 printSummary(*userId);
  238.             }
  239.             //5. balance forecast
  240.             if(loggedinmenuselect ==5) {
  241.                 printSummary(*userId);
  242.             }
  243.             //6. exit
  244.             if(loggedinmenuselect ==6) {
  245.                 //savedata
  246.                 //break;    Break;  Break;
  247.             }
  248.         }
  249. }
  250.  
  251. bool saveAccount()
  252. {
  253.     std::cout << "test";
  254. }
  255.  
  256. int main()
  257. {
  258.     time_t _time;
  259.     struct tm timeinfo;
  260.     time ( &_time );
  261.     localtime_s (&timeinfo,&_time);
  262.  
  263.     // loops and menu initialisation
  264.     int n = 0;
  265.     int menuInput = 0;
  266.  
  267.                     //top level menu
  268.     int subMenuInput = 2;           //logged in account level menu
  269.     int loggedIn = 0;
  270.  
  271.     // user account details
  272.     int inputInt = 0;
  273.     int userId = 10000;
  274.  
  275.     std::cout << "Welcome to Interbanking Proprietary limited Super Squad" << std::endl;    //Welcome Message
  276.     //createAccount(&n);   
  277.     while(loggedIn == 0) // present the menu screen until the user logs in
  278.     {      
  279.         std::cout << "Please select from the following menu"    <<std::endl;    //Welcome Menu
  280.         std::cout << "1. Log in with existing bank account."    <<std::endl;
  281.         std::cout << "2. Create new bank account."              <<std::endl;
  282.         std::cin  >> menuInput;
  283.         if(menuInput == 1)
  284.         {
  285.             login(&n, &loggedIn); // end option 1      
  286.         }
  287.         if(menuInput == 2)
  288.         {
  289.             createAccount(&n); 
  290.             menuInput = 0;     
  291.         }
  292.        
  293.         login(&userId, &loggedIn);
  294.        
  295.     } // end loggedIn loop
  296.  
  297. } // end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement