Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include "stdlib.h"
- #include <iomanip>
- using namespace std;
- void runUsername();
- void runPassword();
- void mainMenu();
- void exit();
- void helpMenu();
- void exitHelp();
- int main() {
- runUsername();
- return 0;
- }
- void runUsername() {
- string correct_username = "username";
- string username;
- int attempt = 1;
- while (attempt <= 3) {
- cout << "Enter your username to continue: ";
- cin >> username;
- attempt = attempt + 1;
- if (cin.fail()) {
- cin.clear();
- cout << "Input Error. Numeric values only!" << endl;
- runUsername();
- }
- else if (username != correct_username) {
- cout << "Incorrect username. Please Try again." << "\n";
- }
- else
- {
- break;
- }
- }
- if (attempt >= 3) {
- if (username == correct_username) {
- cout << "Access Granted." << endl;
- runPassword();
- }
- else {
- exit(0);
- }
- }
- else {
- cout << "Access Granted." << endl;
- runPassword();
- }
- }
- void runPassword() {
- string correct_password = "password";
- string password;
- int attempt = 1;
- while (attempt <= 3) {
- cout << "Enter your password to continue: ";
- cin >> password;
- attempt = attempt + 1;
- if (cin.fail()) {
- cin.clear();
- cout << "Input Error. Numeric values only!" << endl;
- runPassword();
- }
- else if (password != correct_password) {
- cout << "Incorrect password combination. Please Try again." << "\n";
- }
- else
- {
- break;
- }
- }
- if (attempt >= 3) {
- if (password == correct_password) {
- cout << "Access Granted." << endl;
- mainMenu();
- }
- else {
- exit(0);
- }
- }
- else {
- cout << "Access Granted." << endl;
- mainMenu();
- }
- }
- void exit() {
- char choice;
- cout << "\n\n\n" << "Do you want to go back to the main menu? (Y or N): ";
- cin >> choice;
- if (choice == 'Y' || choice == 'y') {
- system("cls");
- mainMenu();
- }
- else if (choice == 'N' || choice == 'n') {
- exit(0);
- }
- else {
- cout << "\n" << "Invalid letter. Only accept Y or N" << "\n";
- exit();
- }
- }
- void mainMenu() {
- int MainMenuOptions;
- do {
- system("cls");
- for (int i = 0; i < 30; ++i) { cout << "-"; }
- cout << "\n" << "Main Menu";
- cout << "\n" << "";
- cout << "\n" << "1. Help Menu";
- cout << "\n" << "2. Customer Details";
- cout << "\n" << "3. Calculation Details";
- cout << "\n" << "4. Customer Profile";
- cout << "\n" << "";
- cout << "\n" << "0. Exit Program";
- cout << "\n" << "" << endl;
- for (int i = 0; i < 30; ++i) { cout << "-"; }
- cout << "\n" << "Please select an option: ";
- cin >> MainMenuOptions;
- if (cin.fail()) {
- cin.clear();
- cout << "Input Error, Numeric values only." << endl;
- system("pause");
- system("cls");
- mainMenu();
- }
- else {
- switch (MainMenuOptions) {
- case 1:
- helpMenu();
- break;
- case 2:
- customerDetails();
- break;
- case 3:
- cout << "Please die"; //calcDetails();
- break;
- case 4:
- customerProfile();
- break;
- case 0:
- exit();
- break;
- default:
- cout << "\n" << "Invalid Option entered" << "\n";
- system("pause");
- system("cls");
- mainMenu();
- break;
- }
- }
- } while (MainMenuOptions != 1 && MainMenuOptions != 2 && MainMenuOptions != 3 && MainMenuOptions != 0);
- }
- void helpMenu() {
- int helpMenuOptions;
- do {
- for (int i = 0; i < 32; ++i) { cout << "-"; }
- cout << "\n" << "Help Menu";
- cout << "\n" << "";
- cout << "\n" << "1. Question 1";
- cout << "\n" << "2. Question 2";
- cout << "\n" << "3. Question 3";
- cout << "\n" << "4. Question 4";
- cout << "\n" << "5. Question 5";
- cout << "\n" << "6. Question 6";
- cout << "\n" << "";
- cout << "\n" << "0. Exit Program";
- cout << "\n" << "" << endl;
- for (int i = 0; i < 32; ++i) { cout << "-"; }
- cout << "\n" << "Please select an option: ";
- cin >> helpMenuOptions;
- if (cin.fail()) {
- cin.clear();
- cout << "Input Error, Numeric values only." << endl;
- system("pause");
- system("cls");
- mainMenu();
- }
- else {
- switch (helpMenuOptions) {
- case 1:
- q1(); //change
- break;
- case 2:
- q2(); //change
- break;
- case 3:
- q3(); //change
- break;
- case 4:
- q4(); //change
- break;
- case 5:
- q5(); //change
- case 6:
- q6(); //change
- break;
- case 0:
- exit();
- break;
- default:
- cout << "\n" << "Invalid Option entered" << "\n";
- system("pause");
- system("cls");
- mainMenu();
- break;
- }
- }
- } while (helpMenuOptions != 1 && helpMenuOptions != 2 && helpMenuOptions != 3 && helpMenuOptions != 0);
- }
- void exitHelp() {
- char choice;
- cout << "\n\n\n" << "Would you like to go back to the help menu? (Y or N): ";
- cin >> choice;
- if (choice == 'Y' || choice == 'y') {
- system("cls");
- helpMenu();
- }
- else if (choice == 'N' || choice == 'n') {
- char choice;
- cout << "\n\n\n" << "Would you like to go back to the main menu? (Y or N)";
- cin >> choice;
- if (choice == 'Y' || choice == 'y') {
- system("cls");
- mainMenu();
- }
- else if (choice == 'N' || choice == 'n') {
- exit(0);
- }
- }
- else {
- cout << "\n" << "Invalid letter. Only accept Y or N" << "\n";
- exit();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement