Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <string>
- using namespace std;
- // function prototypes
- void printIntroMenu();
- void printMainMenu();
- void start();
- void login();
- void createAccount();
- void depositMoney();
- void withdrawMoney();
- void requestBalance();
- // global variable (use this variable to store the user’s menu selection)
- int menuInput, input;
- string user = "ADMIN", pass = "admin", useri, passi;
- int login_access = 0;
- double money=0, amount;
- int main() {
- start();
- }
- void printIntroMenu() {//mainmenu
- cout << "Please select an option from the menu below:\n\n" << "1 -> Login\n" << "2 -> Create New Account\n" << "3 -> Quit\n\n" << ">";
- cin >> menuInput;
- }
- void printMainMenu() {
- cout << "1 -> Deposit Money" << endl << "2 -> Withdraw Money" << endl << "3 -> Request Balance" << endl << "4 -> Quit" << endl << endl << ">" << endl;
- cin >> input;
- switch (input) {//switch statment to trigger additional functions
- case 1://case is used like an if statement here to provide conditions. If the input = 1 , deposit money function will be called
- depositMoney();
- break;
- case 2:
- withdrawMoney();
- break;
- case 3:
- requestBalance();
- break;
- case 4:
- cout << "Goodbye, please come again" << endl;
- }
- }
- void start() {
- printIntroMenu();
- switch (menuInput) {
- case 1:
- login();
- break;
- case 2:
- createAccount();
- start();
- break;
- case 3:
- cout << "Goodbye!" << endl;
- }
- }
- void login() {
- cout << "Username: ";
- cin >> useri;
- cout << "Password: ";
- cin >> passi;
- if (user == useri && pass == passi) {
- cout << "Access Granted\n";
- printMainMenu();
- login_access++;
- } else {
- cout << "ACCESS DENIED";
- }
- }
- void createAccount() {
- cout << "Input a new Username: ";
- cin >> user;
- cout << "Input a new Password: ";
- cin >> pass;
- printIntroMenu();
- }
- void depositMoney() {
- cout << "How much do you want to deposit?";
- cin >> amount;
- money = amount + money;//simple counter to keep track of money
- cout << "You deposited " << amount << " into your bank account." << endl;
- printMainMenu();
- }
- void withdrawMoney() {
- cout << "How much do you want to withdraw?";
- cin >> amount;
- money = money - amount; //subtracts from the counter
- cout << "You withdrew " << amount << " from your bank account." << endl;
- printMainMenu();
- }
- void requestBalance() {
- cout << "You have " << amount << " in your account." << endl;
- printMainMenu(); //brings users back to the main menu
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement