Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include "stdlib.h"
- #include <string>
- #include <iomanip>
- #include <conio.h>
- using namespace std;
- void runUsername();
- void runPassword();
- void menuSelections();
- void helpMenu();
- void customerDetails();
- void MainExit();
- void HelpExit();
- int gymid, tele;
- string name, address, email;
- int main()
- {
- runUsername();
- return 0;
- }
- void runUsername()
- {
- int correct_username = 1990;
- int username = 0;
- int attempt = 1;
- while (attempt <= 3) {
- cout << "Enter your username: ";
- cin >> username;
- attempt = attempt + 1;
- if (cin.fail())
- {
- cin.clear();
- cin.ignore(INT_MAX, '\n');
- cout << "Input Error. Numeric values only" << endl;
- runUsername();
- }
- else if (username != correct_username) {
- cout << "Incorrect password combination. Please try again." << "\n";
- runUsername();
- }
- else
- {
- break;
- }
- }
- if (attempt >= 3)
- {
- if (username == correct_username)
- {
- cout << "Access granted." << endl;
- system("Pause");
- runPassword();
- }
- else
- {
- exit(0);
- }
- }
- else
- {
- cout << "Access granted." << endl;
- system("Pause");
- runPassword();
- }
- }
- void runPassword()
- {
- int correct_password = 1998;
- int password = 0;
- int attempt = 1;
- while (attempt <= 3) {
- cout << "Enter your password: ";
- cin >> password;
- attempt = attempt + 1;
- if (cin.fail())
- {
- cin.clear();
- cin.ignore(INT_MAX, '\n');
- cout << "Input Error. Numeric values only" << endl;
- runPassword();
- }
- else if (password != correct_password) {
- cout << "Incorrect password combination. Please try again." << "\n";
- //runPassword();
- }
- else
- {
- break;
- }
- }
- if (attempt >= 3)
- {
- if (password == correct_password)
- {
- cout << "Access granted." << endl;
- system("Pause");
- menuSelections();
- }
- else
- {
- exit(0);
- }
- }
- else
- {
- cout << "Access granted." << endl;
- system("Pause");
- menuSelections();
- }
- }
- void menuSelections()
- {
- int MainMenuOptions;
- //do-while loop starts here.that display menu again and again until user select to exit program
- do
- {
- cout << "\n" << "| Menu Items |";
- cout << "\n" << "| |";
- cout << "\n" << "| 1. Help Menu |";
- cout << "\n" << "| 2. Customer Details |";
- cout << "\n" << "| 3. Do Loop (Post Check) |";
- cout << "\n" << "| |";
- cout << "\n" << "| 0. Exit program |";
- cout << "\n" << "| |" << "\n";
- for (int i = 0; i < 30; ++i)
- {
- cout << "-";
- }
- //Prompting user to enter an option according to menu
- cout << "\n" << "Please select an option : ";
- cin >> MainMenuOptions; // taking option value as input and saving in variable "option"
- if (cin.fail())
- {
- cin.clear();
- cin.ignore(INT_MAX, '\n');
- cout << "Input Error. Numeric values only" << endl;
- system("pause");
- system("cls");
- menuSelections();
- }
- else
- {
- switch (MainMenuOptions)
- {
- case 1:
- helpMenu();
- break;
- case 2:
- customerDetails();
- break;
- case 3:
- break;
- case 0:
- break;
- default:
- cout << "\n" << "Invalid Option entered" << "\n";
- system("pause");
- system("cls");
- menuSelections();
- break;
- }
- }
- } while (MainMenuOptions != 1 && MainMenuOptions != 2 && MainMenuOptions != 3 && MainMenuOptions != 0);
- }
- void helpMenu()
- {
- int helpMenu;
- do
- {
- system("cls");
- cout << "\n" << " Help Menu Items ";
- cout << "\n" << " ";
- cout << "\n" << " 1. How to calculate BMR? ";
- cout << "\n" << " 2. How to calculate BMI? ";
- cout << "\n" << " 3. How to calculate kilocalories? ";
- cout << "\n" << " 4. How to calculate calories? ";
- cout << "\n" << " 5. Why customer details are needed? ";
- cout << "\n" << " 6. Edit this? ";
- cout << "\n" << " " << endl;
- cout << "\n" << " 0. Exit";
- for (int i = 0; i < 30; ++i)
- {
- cout << "-";
- }
- cout << "\n" << "Please select an option :";
- cin >> helpMenu;
- if (cin.fail())
- {
- cin.clear();
- cout << "Input Error. Numeric values only" << endl;
- system("pause");
- system("cls");
- menuSelections();
- }
- else
- {
- switch (helpMenu)
- {
- case 1:
- system("cls");
- cout << "\n\n" << "To calculate BMR you have to use this formula BMR = 88.362 + (13.397 x weight in kg) + (4.799 x height in cm)–(5.677 x age in years)" << endl;
- system("pause");
- //HelpExit();
- break;
- case 2:
- system("cls");
- cout << "\n\n" << "To calculate BMI you have to use this formula BMI = Divide Weight (KG) by Height (M) Divide by your Height (M) again" << endl;
- system("pause");
- //HelpExit();
- break;
- case 3:
- system("cls");
- cout << "\n\n" << "To calculate kilocalories you have to use this formula" << endl;
- system("pause");
- //HelpExit();
- case 4:
- system("cls");
- cout << "\n\n" << "To calculate calories you have to use this formula" << endl;
- system("pause");
- //HelpExit();
- case 5:
- system("cls");
- cout << "\n\n" << "You're required to pay 20% VAT" << endl;
- system("pause");
- //HelpExit();
- case 6:
- system("cls");
- cout << "\n\n" << "You're required to pay 20% VAT" << endl;
- system("pause");
- //HelpExit();
- case 0:
- system("cls");
- HelpExit();
- break;
- default:
- system("cls");
- cout << "\n" << "Invalid Option entered" << "\n";
- system("pause");
- system("cls");
- menuSelections();
- break;
- }
- }
- } while (helpMenu != 1 && helpMenu != 2 && helpMenu != 3 && helpMenu != 0);
- }
- void customerDetails() {
- for (int i = 0; i < 32; ++i) { cout << "-"; }
- cout << "\n" << "Customer Details" << endl;
- for (int i = 0; i < 32; ++i) { cout << "-"; }
- cout << "\n" << "Please enter your gym id: ";
- cin >> gymid;
- cout << "\n" << "Please enter your name: ";
- cin >> name;
- cout << "\n" << "Please enter your phone number: ";
- cin >> tele;
- cout << "\n" << "Please enter your email address: ";
- cin >> email;
- cout << "\n" << "Please enter your address: ";
- cin >> address;
- system("pause");
- system("cls");
- menuSelections();
- }
- void customerProfile() {
- }
- void MainExit() {
- 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");
- menuSelections();
- }
- else if (choice == 'N' || choice == 'n') {
- exit(0);
- }
- else {
- cout << "\n" << "Invalid letter.Only accept Y or N";
- exit(0);
- }
- }
- void HelpExit() {
- char choice;
- cout << "\n\n\n" << "Do you want 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') {
- MainExit();
- }
- else {
- cout << "\n" << "Invalid letter.Only accept Y or N";
- exit(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement