Guest User

Untitled

a guest
Dec 6th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <ctime>
  4. #include <conio.h>
  5. #include <stdio.h>
  6.  
  7. struct User {
  8.     int acctNumber1;            //User account number 1
  9.     int acctNumber2;
  10.     double acctBalance1;        //user account balance 1
  11.     double acctBalance2;       
  12.     char acctName[256];         //User account Name
  13.     char acctPass[256];         //user account password
  14.     int logInNumber;
  15.     bool isAdmin;
  16. } account[8999];
  17.  
  18. // functions must be declared before main or we'll have a compilation error
  19. bool accountExists(int acctNumber) {
  20.     for(int i = 0; i < 8999; i++) {
  21.         if(account[i].acctNumber1 == acctNumber)
  22.             return true;
  23.         if(account[i].acctNumber2 == acctNumber)
  24.             return true;
  25.     }
  26.     return false;
  27. }
  28.  
  29. void printSummary(int user) {
  30.     printf("\n\n"
  31.            "+-----------------+\n"
  32.            "| Account Summary |\n"
  33.            "+=================+\n\n"
  34.            "+------------------------------------+\n"
  35.            "| Account | Account number | Balance |\n"
  36.            "+---------+----------------+---------+\n"
  37.            "| 1       | %d           | %.2lf   \n"
  38.            "| 2       | %d           | %.2lf   \n\n\n",
  39.            account[user].acctNumber1, account[user].acctBalance1, account[user].acctNumber2, account[user].acctBalance2);
  40. }
  41.  
  42. void createAccount(int *n) {
  43.     *n = *n + 1;
  44.     int *inputInt = new int[1];
  45.     std::cout << "Please Fill out the following information to create a new account" << std::endl;
  46.     std::cout << "Full name: ";
  47.     std::cin >> account[*n].acctName;
  48.     std::cout << "Password: ";
  49.     std::cin >> account[*n].acctPass;
  50.                
  51.     // get first account number
  52.     std::cout << "First account number: ";
  53.     std::cin >> *inputInt;
  54.     while(*inputInt < 1000 || *inputInt > 9999) { // check none of the users already have this account number, if they do keep prompting
  55.         std::cout << "Account number invalid. Must be between 1000 and 9999.\n"
  56.                 << "------------------------------------------------------\n"
  57.                 << "First account number: ";                   
  58.         std::cin >> *inputInt;
  59.     }
  60.     account[*n].acctNumber1 = *inputInt; // valid (new) account number, add it to the user
  61.  
  62.     // get first account balance
  63.     std::cout << "First account Balance: ";
  64.     std::cin >> account[*n].acctBalance1;
  65.  
  66.     // get second account number
  67.     std::cout << "Second account number: ";
  68.     std::cin >> *inputInt;
  69.     while(*inputInt < 1000 || *inputInt > 8999) { // check none of the users already have this account number, if they do keep prompting
  70.         std::cout << "Account number invalid. Must be between 1000 and 9999.\n"
  71.                 << "------------------------------------------------------\n"
  72.                 << "Second account number: ";
  73.         std::cin >> *inputInt;
  74.     }
  75.     account[*n].acctNumber2 = *inputInt; // valid (new) account number, add it to the user
  76.  
  77.     //get second account balance
  78.     std::cout << "Second account balance: ";
  79.     std::cin >> account[*n].acctBalance2;
  80.  
  81.     printSummary(*n);
  82. }
  83.  
  84. void login(int *n, 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[*n].acctName << ", Please enter your password: " << std::endl;
  91.             std::cin >> inputText;
  92.             if ( strcmp (account[i].acctPass, inputText) == 0 ) {
  93.                 printSummary(*n);
  94.                 getch();
  95.                 *loggedIn = 1;
  96.                 account[*n].logInNumber++;
  97.             }
  98.             else {
  99.                 std::cout << "Incorrect password." << std::endl;
  100.                 break;
  101.             }
  102.         }
  103.     }
  104. }
  105.  
  106. int main()
  107. {
  108.     time_t t = time(0);         // get time now
  109.     struct tm * now = localtime( & t );
  110.  
  111.     // loops and menu initialisation
  112.     int n = 0;
  113.     int menuInput = 0;              //top level menu
  114.     int subMenuInput = 0;           //logged in account level menu
  115.     int loggedIn = 0;
  116.  
  117.     // user account details
  118.     int inputInt = 0;
  119.     char inputText[256];
  120.  
  121.     //Balance Transfer decs
  122.     int fromaccount;
  123.     int toaccount;
  124.     double transferAmount; 
  125.  
  126.     std::cout << "Welcome to Interbanking Proprietary limited Super Squad" << std::endl;    //Welcome Message
  127.     while (!loggedIn) // present the menu screen until the user logs in
  128.     {
  129.         std::cout << "Please select from the following menu" <<std::endl;                       //Welcome Menu
  130.         std::cout << "1. Log in with existing bank account." <<std::endl;
  131.         std::cout << "2. Create new bank account." <<std::endl;
  132.         std::cin     >> menuInput;
  133.    
  134.         switch(menuInput)
  135.         {
  136.             case 1:
  137.                 login(&n, &loggedIn);
  138.             break; // end option 1     
  139.             case 2:            
  140.                 createAccount(&n);     
  141.                 // reset menu
  142.                 menuInput = 0;
  143.             break;      } // end switch menuInput
  144.     } // end loggedIn loop
  145. } // end main
Add Comment
Please, Sign In to add comment