Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <ctime>
- #include <conio.h>
- #include <stdio.h>
- struct User {
- int acctNumber1; //User account number 1
- int acctNumber2;
- double acctBalance1; //user account balance 1
- double acctBalance2;
- char acctName[256]; //User account Name
- char acctPass[256]; //user account password
- int logInNumber;
- bool isAdmin;
- } account[8999];
- // functions must be declared before main or we'll have a compilation error
- bool accountExists(int acctNumber) {
- for(int i = 0; i < 8999; i++) {
- if(account[i].acctNumber1 == acctNumber)
- return true;
- if(account[i].acctNumber2 == acctNumber)
- return true;
- }
- return false;
- }
- void printSummary(int user) {
- printf("\n\n"
- "+-----------------+\n"
- "| Account Summary |\n"
- "+=================+\n\n"
- "+------------------------------------+\n"
- "| Account | Account number | Balance |\n"
- "+---------+----------------+---------+\n"
- "| 1 | %d | %.2lf \n"
- "| 2 | %d | %.2lf \n\n\n",
- account[user].acctNumber1, account[user].acctBalance1, account[user].acctNumber2, account[user].acctBalance2);
- }
- void createAccount(int *n) {
- *n = *n + 1;
- int *inputInt = new int[1];
- std::cout << "Please Fill out the following information to create a new account" << std::endl;
- std::cout << "Full name: ";
- std::cin >> account[*n].acctName;
- std::cout << "Password: ";
- std::cin >> account[*n].acctPass;
- // get first account number
- std::cout << "First account number: ";
- std::cin >> *inputInt;
- while(*inputInt < 1000 || *inputInt > 9999) { // check none of the users already have this account number, if they do keep prompting
- std::cout << "Account number invalid. Must be between 1000 and 9999.\n"
- << "------------------------------------------------------\n"
- << "First account number: ";
- std::cin >> *inputInt;
- }
- account[*n].acctNumber1 = *inputInt; // valid (new) account number, add it to the user
- // get first account balance
- std::cout << "First account Balance: ";
- std::cin >> account[*n].acctBalance1;
- // get second account number
- std::cout << "Second account number: ";
- std::cin >> *inputInt;
- while(*inputInt < 1000 || *inputInt > 8999) { // check none of the users already have this account number, if they do keep prompting
- std::cout << "Account number invalid. Must be between 1000 and 9999.\n"
- << "------------------------------------------------------\n"
- << "Second account number: ";
- std::cin >> *inputInt;
- }
- account[*n].acctNumber2 = *inputInt; // valid (new) account number, add it to the user
- //get second account balance
- std::cout << "Second account balance: ";
- std::cin >> account[*n].acctBalance2;
- printSummary(*n);
- }
- void login(int *n, int *loggedIn) {
- char *inputText = new char[256];
- std::cout << "Please enter username: ";
- std::cin >> inputText;
- for(int i = 0; i < 8999; i++) {
- if ( strcmp (account[i].acctName, inputText) == 0 ) {
- std::cout << "Welcome " << account[*n].acctName << ", Please enter your password: " << std::endl;
- std::cin >> inputText;
- if ( strcmp (account[i].acctPass, inputText) == 0 ) {
- printSummary(*n);
- getch();
- *loggedIn = 1;
- account[*n].logInNumber++;
- }
- else {
- std::cout << "Incorrect password." << std::endl;
- break;
- }
- }
- }
- }
- int main()
- {
- time_t t = time(0); // get time now
- struct tm * now = localtime( & t );
- // loops and menu initialisation
- int n = 0;
- int menuInput = 0; //top level menu
- int subMenuInput = 0; //logged in account level menu
- int loggedIn = 0;
- // user account details
- int inputInt = 0;
- char inputText[256];
- //Balance Transfer decs
- int fromaccount;
- int toaccount;
- double transferAmount;
- std::cout << "Welcome to Interbanking Proprietary limited Super Squad" << std::endl; //Welcome Message
- while (!loggedIn) // present the menu screen until the user logs in
- {
- std::cout << "Please select from the following menu" <<std::endl; //Welcome Menu
- std::cout << "1. Log in with existing bank account." <<std::endl;
- std::cout << "2. Create new bank account." <<std::endl;
- std::cin >> menuInput;
- switch(menuInput)
- {
- case 1:
- login(&n, &loggedIn);
- break; // end option 1
- case 2:
- createAccount(&n);
- // reset menu
- menuInput = 0;
- break; } // end switch menuInput
- } // end loggedIn loop
- } // end main
Add Comment
Please, Sign In to add comment