Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // eastsurreygym.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include "stdlib.h"
- #include <string>
- #include <iomanip>
- #include <conio.h>
- #include <fstream>
- #include <istream>
- using namespace std;
- void runUsername();
- void runPassword();
- void menuSelections();
- void helpMenu();
- void customerDetails();
- void customerProfile();
- void calculations();
- void calculations2();
- void MainExit();
- void HelpExit();
- void option1();
- void option2();
- void kilo();
- double enterMeasurements(double&H);
- double enterMeasurements2(double&W);
- double enterMeasurements3(double&A);
- double weight, height, age, bmi, bmr, kiloC, targetbmi;
- string name, address, email, gymid, tele, bmiCat;
- 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. Customer Profile |";
- cout << "\n" << "| 4. Calculations |";
- 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:
- customerProfile();
- break;
- case 4:
- calculations();
- 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. Why height is measured in Centimeters? ";
- 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" << "To get a better understanding of the individual" << endl;
- system("pause");
- HelpExit();
- case 6:
- system("cls");
- cout << "\n\n" << "It is much more specific than doing it in Meters" << 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 << "-"; }
- cin.ignore();
- cout << "\n" << "Please enter your gym id: ";
- getline(cin, gymid);
- cout << "\n" << "Please enter your name: ";
- getline(cin, name);
- cout << "\n" << "Please enter your phone number: ";
- getline(cin, tele);
- cout << "\n" << "Please enter your address: ";
- getline(cin, address);
- //cout << gymid + name + tele + email + address;
- system("pause");
- system("cls");
- menuSelections();
- }
- void customerProfile() {
- system("cls");
- for (int i = 0; i < 32; ++i) { cout << "-"; }
- cout << "\n" << "Gym ID: " << gymid;
- cout << "\n" << "Name: " << name;
- cout << "\n" << "Telephone Number: " << tele;
- cout << "\n" << "Email Address: " << email;
- cout << "\n" << "Address: " << address;
- cout << "\n" << "BMI: " << bmi;
- cout << "\n" << "BMR: " << bmr;
- cout << "\n" << "Target BMI: " << targetbmi;
- cout << "\n" << "";
- for (int i = 0; i < 32; ++i) { cout << "-"; }
- cout << "\n" << "";
- system("pause");
- system("cls");
- menuSelections();
- }
- 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);
- }
- }
- double enterMeasurements(double&H) {
- system("cls");
- cout << "\n" << "Please enter your height between 120 - 210 (in cm): ";
- cin >> H;
- if (cin.fail())
- {
- cin.clear();
- cin.ignore(INT_MAX, '\n');
- cout << "Input Error. Numeric values only" << endl;
- system("pause");
- system("cls");
- enterMeasurements(H);
- }
- else if (H < 120 || H>210)
- {
- cout << "Number has to be between 120 - 210cm" << endl;
- system("pause");
- system("cls");
- enterMeasurements(H);
- }
- else
- {
- return H;
- }
- return H;
- return H;
- }
- double enterMeasurements2(double&W) {
- system("cls");
- cout << "\n" << "Please enter your weight between 30 - 250 (in kg): ";
- cin >> W;
- if (cin.fail())
- {
- cin.clear();
- cin.ignore(INT_MAX, '\n');
- cout << "Input Error. Numeric values only" << endl;
- system("pause");
- system("cls");
- enterMeasurements2(W);
- }
- else if (W < 30 || W>250)
- {
- cout << "Number has to be between 30 - 250kg" << endl;
- system("pause");
- system("cls");
- enterMeasurements2(W);
- }
- else
- {
- return W;
- }
- return W;
- }
- double enterMeasurements3(double&A) {
- system("cls");
- cout << "\n" << "Please enter your age between 14 - 100: ";
- cin >> A;
- if (cin.fail())
- {
- cin.clear();
- cin.ignore(INT_MAX, '\n');
- cout << "Input Error. Numeric values only" << endl;
- system("pause");
- system("cls");
- enterMeasurements3(A);
- }
- else if (A < 14 || A>100)
- {
- cout << "Age has to be between 14 - 100" << endl;
- system("pause");
- system("cls");
- enterMeasurements3(A);
- }
- else
- {
- return A;
- }
- return A;
- }
- void calculations() {
- double H, W, A;
- enterMeasurements(H);
- enterMeasurements2(W);
- enterMeasurements3(A);
- weight = W;
- height = H;
- age = A;
- bmi = W / (H / 100 * H / 100);
- if (bmi < 18.5) {
- bmiCat = "Underweight";
- targetbmi = bmi + 2;
- }
- else if (bmi > 18.5 && bmi < 24.9) {
- bmiCat = "Normal weight";
- targetbmi = 22;
- }
- else if (bmi > 25 && bmi < 29.9) {
- bmiCat = "Overweight";
- targetbmi = bmi - 1;
- }
- else if (bmi > 30) {
- bmiCat = "Obese";
- targetbmi = bmi - 2;
- }
- cout << "\n" << "Your BMI is " << bmi << "kg/m" << char(253);
- cout << "\n" << "Your BMI catagory is " << bmiCat;
- cout << "\n" << "Your target BMI is " << targetbmi << "kg/m" << char(253) << endl;
- system("pause");
- calculations2();
- }
- void calculations2() {
- int calc2options;
- do {
- for (int i = 0; i < 30; i++) { cout << "-"; }
- cout << "\n" << "Are you male or female?";
- cout << "\n" << "1. Male";
- cout << "\n" << "2. Female";
- cout << "\n" << "Please select an option: ";
- cin >> calc2options;
- if (cin.fail()) {
- cin.clear();
- cout << "Input Error, Numeric values only." << endl;
- system("pause");
- system("cls");
- menuSelections();
- }
- else {
- switch (calc2options) {
- case 1:
- option1();
- break;
- case 2:
- option2();
- break;
- case 0:
- exit(0);
- break;
- default:
- cout << "\n" << "Invalid Option Entered" << "\n";
- system("pause");
- system("cls");
- menuSelections();
- break;
- }
- }
- } while (calc2options != 1 && calc2options != 2 && calc2options != 0);
- }
- void option1() {
- bmr = 88.362 + (13.397 * weight) + (4.799 * height) - (5.677 * age);
- cout << "\n" << "Your BMR is: " << bmr << endl;
- system("pause");
- kilo();
- }
- void option2() {
- bmr = 447.593 + (9.247 * weight) + (3.098 * height) - (4.330 * age);
- cout << "\n" << "Your BMR is: " << bmr << endl;
- system("pause");
- kilo();
- }
- void kilo() {
- int kiloOptions;
- do {
- cout << "\n" << "How much exercise do you do?";
- cout << "\n" << "1. Very little to no exercise";
- cout << "\n" << "2. Little exercise (1-2) days a week";
- cout << "\n" << "3. Medium exercise (3-5) days a week";
- cout << "\n" << "4. High exercise (4-6) days a week";
- cout << "\n" << "5. Intense exercise (7) days a week 2 times a day";
- cout << "\n" << "Please choose an option: ";
- cin >> kiloOptions;
- if (cin.fail()) {
- cin.clear();
- cout << "Input Error, Numeric values only. " << endl;
- system("pause");
- system("cls");
- menuSelections();
- }
- else {
- switch (kiloOptions) {
- case 1:
- kiloC = bmr * 1.2;
- cout << "\n" << "Returning to menu" << endl;
- menuSelections();
- break;
- case 2:
- kiloC = bmr * 1.375;
- cout << "\n" << "Returning to menu" << endl;
- menuSelections();
- break;
- case 3:
- kiloC = bmr * 1.55;
- cout << "\n" << "Returning to menu" << endl;
- menuSelections();
- break;
- case 4:
- kiloC = bmr * 1.725;
- cout << "\n" << "Returning to menu" << endl;
- menuSelections();
- break;
- case 5:
- kiloC = bmr * 1.9;
- cout << "\n" << "Returning to menu" << endl;
- menuSelections();
- break;
- case 0:
- exit(0);
- break;
- default:
- cout << "\n" << "Incorrect option entered" << "\n";
- system("pause");
- system("cls");
- menuSelections();
- break;
- }
- }
- } while (kiloOptions != 1 && kiloOptions != 2 && kiloOptions != 3 && kiloOptions != 4 && kiloOptions != 5 && kiloOptions != 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement