Advertisement
Guest User

Untitled

a guest
Feb 9th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.17 KB | None | 0 0
  1. // eastsurreygym.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include "stdlib.h"
  7. #include <string>
  8. #include <iomanip>
  9. #include <conio.h>
  10. #include <fstream>
  11. #include <istream>
  12.  
  13. using namespace std;
  14.  
  15.  
  16. void runUsername();
  17. void runPassword();
  18. void menuSelections();
  19. void helpMenu();
  20. void customerDetails();
  21. void customerProfile();
  22. void calculations();
  23. void calculations2();
  24. void MainExit();
  25. void HelpExit();
  26. void option1();
  27. void option2();
  28. void kilo();
  29. double enterMeasurements(double&H);
  30. double enterMeasurements2(double&W);
  31. double enterMeasurements3(double&A);
  32. double weight, height, age, bmi, bmr, kiloC, targetbmi;
  33. string name, address, email, gymid, tele, bmiCat;
  34.  
  35. int main()
  36. {
  37. runUsername();
  38. return 0;
  39. }
  40.  
  41. void runUsername()
  42. {
  43. int correct_username = 1990;
  44. int username = 0;
  45. int attempt = 1;
  46.  
  47. while (attempt <= 3) {
  48. cout << "Enter your username: ";
  49. cin >> username;
  50. attempt = attempt + 1;
  51.  
  52. if (cin.fail())
  53. {
  54. cin.clear();
  55. cin.ignore(INT_MAX, '\n');
  56. cout << "Input Error. Numeric values only" << endl;
  57. runUsername();
  58. }
  59. else if (username != correct_username) {
  60. cout << "Incorrect password combination. Please try again." << "\n";
  61. runUsername();
  62. }
  63. else
  64. {
  65. break;
  66. }
  67. }
  68. if (attempt >= 3)
  69. {
  70. if (username == correct_username)
  71. {
  72. cout << "Access granted." << endl;
  73. system("Pause");
  74. runPassword();
  75. }
  76. else
  77. {
  78. exit(0);
  79. }
  80. }
  81. else
  82. {
  83. cout << "Access granted." << endl;
  84. system("Pause");
  85. runPassword();
  86. }
  87. }
  88.  
  89. void runPassword()
  90. {
  91. int correct_password = 1998;
  92. int password = 0;
  93. int attempt = 1;
  94.  
  95. while (attempt <= 3) {
  96. cout << "Enter your password: ";
  97. cin >> password;
  98. attempt = attempt + 1;
  99.  
  100. if (cin.fail())
  101. {
  102. cin.clear();
  103. cin.ignore(INT_MAX, '\n');
  104. cout << "Input Error. Numeric values only" << endl;
  105. runPassword();
  106. }
  107. else if (password != correct_password) {
  108. cout << "Incorrect password combination. Please try again." << "\n";
  109. //runPassword();
  110. }
  111. else
  112. {
  113. break;
  114. }
  115. }
  116. if (attempt >= 3)
  117. {
  118. if (password == correct_password)
  119. {
  120. cout << "Access granted." << endl;
  121. system("Pause");
  122. menuSelections();
  123. }
  124. else
  125. {
  126. exit(0);
  127. }
  128. }
  129. else
  130. {
  131. cout << "Access granted." << endl;
  132. system("Pause");
  133. menuSelections();
  134. }
  135. }
  136.  
  137. void menuSelections()
  138. {
  139. int MainMenuOptions;
  140. //do-while loop starts here.that display menu again and again until user select to exit program
  141. do
  142. {
  143. cout << "\n" << "| Menu Items |";
  144. cout << "\n" << "| |";
  145. cout << "\n" << "| 1. Help Menu |";
  146. cout << "\n" << "| 2. Customer Details |";
  147. cout << "\n" << "| 3. Customer Profile |";
  148. cout << "\n" << "| 4. Calculations |";
  149. cout << "\n" << "| |";
  150. cout << "\n" << "| 0. Exit program |";
  151. cout << "\n" << "| |" << "\n";
  152.  
  153. for (int i = 0; i < 30; ++i)
  154. {
  155. cout << "-";
  156. }
  157. //Prompting user to enter an option according to menu
  158. cout << "\n" << "Please select an option : ";
  159. cin >> MainMenuOptions; // taking option value as input and saving in variable "option"
  160. if (cin.fail())
  161. {
  162. cin.clear();
  163. cin.ignore(INT_MAX, '\n');
  164. cout << "Input Error. Numeric values only" << endl;
  165. system("pause");
  166. system("cls");
  167. menuSelections();
  168. }
  169. else
  170. {
  171. switch (MainMenuOptions)
  172. {
  173. case 1:
  174. helpMenu();
  175. break;
  176. case 2:
  177. customerDetails();
  178. break;
  179. case 3:
  180. customerProfile();
  181. break;
  182. case 4:
  183. calculations();
  184. break;
  185. case 0:
  186. break;
  187. default:
  188. cout << "\n" << "Invalid Option entered" << "\n";
  189. system("pause");
  190. system("cls");
  191. menuSelections();
  192. break;
  193. }
  194. }
  195. } while (MainMenuOptions != 1 && MainMenuOptions != 2 && MainMenuOptions != 3 && MainMenuOptions != 0);
  196. }
  197.  
  198. void helpMenu()
  199. {
  200. int helpMenu;
  201.  
  202. do
  203. {
  204. system("cls");
  205. cout << "\n" << " Help Menu Items ";
  206. cout << "\n" << " ";
  207. cout << "\n" << " 1. How to calculate BMR? ";
  208. cout << "\n" << " 2. How to calculate BMI? ";
  209. cout << "\n" << " 3. How to calculate kilocalories? ";
  210. cout << "\n" << " 4. How to calculate calories? ";
  211. cout << "\n" << " 5. Why customer details are needed? ";
  212. cout << "\n" << " 6. Why height is measured in Centimeters? ";
  213. cout << "\n" << " " << endl;
  214. cout << "\n" << " 0. Exit";
  215.  
  216. for (int i = 0; i < 30; ++i)
  217. {
  218. cout << "-";
  219. }
  220.  
  221. cout << "\n" << "Please select an option :";
  222. cin >> helpMenu;
  223. if (cin.fail())
  224. {
  225. cin.clear();
  226.  
  227. cout << "Input Error. Numeric values only" << endl;
  228. system("pause");
  229. system("cls");
  230. menuSelections();
  231. }
  232. else
  233. {
  234. switch (helpMenu)
  235. {
  236. case 1:
  237. system("cls");
  238. 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;
  239. system("pause");
  240. HelpExit();
  241. break;
  242. case 2:
  243. system("cls");
  244. 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;
  245. system("pause");
  246. HelpExit();
  247. break;
  248. case 3:
  249. system("cls");
  250. cout << "\n\n" << "To calculate kilocalories you have to use this formula" << endl;
  251. system("pause");
  252. HelpExit();
  253. case 4:
  254. system("cls");
  255. cout << "\n\n" << "To calculate calories you have to use this formula" << endl;
  256. system("pause");
  257. HelpExit();
  258. case 5:
  259. system("cls");
  260. cout << "\n\n" << "To get a better understanding of the individual" << endl;
  261. system("pause");
  262. HelpExit();
  263. case 6:
  264. system("cls");
  265. cout << "\n\n" << "It is much more specific than doing it in Meters" << endl;
  266. system("pause");
  267. HelpExit();
  268. case 0:
  269. system("cls");
  270. HelpExit();
  271. break;
  272. default:
  273. system("cls");
  274. cout << "\n" << "Invalid Option entered" << "\n";
  275. system("pause");
  276. system("cls");
  277. menuSelections();
  278. break;
  279. }
  280. }
  281. } while (helpMenu != 1 && helpMenu != 2 && helpMenu != 3 && helpMenu != 0);
  282. }
  283.  
  284. void customerDetails() {
  285. for (int i = 0; i < 32; ++i) { cout << "-"; }
  286. cout << "\n" << "Customer Details" << endl;
  287. for (int i = 0; i < 32; ++i) { cout << "-"; }
  288. cin.ignore();
  289. cout << "\n" << "Please enter your gym id: ";
  290. getline(cin, gymid);
  291. cout << "\n" << "Please enter your name: ";
  292. getline(cin, name);
  293. cout << "\n" << "Please enter your phone number: ";
  294. getline(cin, tele);
  295. cout << "\n" << "Please enter your address: ";
  296. getline(cin, address);
  297.  
  298.  
  299. //cout << gymid + name + tele + email + address;
  300.  
  301. system("pause");
  302. system("cls");
  303. menuSelections();
  304. }
  305.  
  306. void customerProfile() {
  307. system("cls");
  308. for (int i = 0; i < 32; ++i) { cout << "-"; }
  309. cout << "\n" << "Gym ID: " << gymid;
  310. cout << "\n" << "Name: " << name;
  311. cout << "\n" << "Telephone Number: " << tele;
  312. cout << "\n" << "Email Address: " << email;
  313. cout << "\n" << "Address: " << address;
  314. cout << "\n" << "BMI: " << bmi;
  315. cout << "\n" << "BMR: " << bmr;
  316. cout << "\n" << "Target BMI: " << targetbmi;
  317. cout << "\n" << "";
  318. for (int i = 0; i < 32; ++i) { cout << "-"; }
  319. cout << "\n" << "";
  320.  
  321. system("pause");
  322. system("cls");
  323. menuSelections();
  324. }
  325.  
  326. void MainExit() {
  327. char choice;
  328. cout << "\n\n\n" << "Do you want to go back to the main menu (y or n):";
  329. cin >> choice;
  330. if (choice == 'Y' || choice == 'y') {
  331. system("cls");
  332. menuSelections();
  333. }
  334. else if (choice == 'N' || choice == 'n') {
  335. exit(0);
  336. }
  337. else {
  338. cout << "\n" << "Invalid letter.Only accept Y or N";
  339. exit(0);
  340. }
  341. }
  342. void HelpExit() {
  343. char choice;
  344. cout << "\n\n\n" << "Do you want to go back to the help menu (y or n):";
  345. cin >> choice;
  346. if (choice == 'Y' || choice == 'y') {
  347. system("cls");
  348. helpMenu();
  349. }
  350. else if (choice == 'N' || choice == 'n') {
  351. MainExit();
  352. }
  353. else {
  354. cout << "\n" << "Invalid letter.Only accept Y or N";
  355. exit(0);
  356. }
  357. }
  358. double enterMeasurements(double&H) {
  359. system("cls");
  360. cout << "\n" << "Please enter your height between 120 - 210 (in cm): ";
  361. cin >> H;
  362. if (cin.fail())
  363. {
  364. cin.clear();
  365. cin.ignore(INT_MAX, '\n');
  366. cout << "Input Error. Numeric values only" << endl;
  367. system("pause");
  368. system("cls");
  369. enterMeasurements(H);
  370. }
  371. else if (H < 120 || H>210)
  372. {
  373. cout << "Number has to be between 120 - 210cm" << endl;
  374. system("pause");
  375. system("cls");
  376. enterMeasurements(H);
  377. }
  378. else
  379. {
  380. return H;
  381. }
  382. return H;
  383.  
  384.  
  385.  
  386. return H;
  387. }
  388. double enterMeasurements2(double&W) {
  389. system("cls");
  390. cout << "\n" << "Please enter your weight between 30 - 250 (in kg): ";
  391. cin >> W;
  392. if (cin.fail())
  393. {
  394. cin.clear();
  395. cin.ignore(INT_MAX, '\n');
  396. cout << "Input Error. Numeric values only" << endl;
  397. system("pause");
  398. system("cls");
  399. enterMeasurements2(W);
  400. }
  401. else if (W < 30 || W>250)
  402. {
  403. cout << "Number has to be between 30 - 250kg" << endl;
  404. system("pause");
  405. system("cls");
  406. enterMeasurements2(W);
  407. }
  408. else
  409. {
  410. return W;
  411. }
  412. return W;
  413. }
  414. double enterMeasurements3(double&A) {
  415. system("cls");
  416. cout << "\n" << "Please enter your age between 14 - 100: ";
  417. cin >> A;
  418. if (cin.fail())
  419. {
  420. cin.clear();
  421. cin.ignore(INT_MAX, '\n');
  422. cout << "Input Error. Numeric values only" << endl;
  423. system("pause");
  424. system("cls");
  425. enterMeasurements3(A);
  426. }
  427. else if (A < 14 || A>100)
  428. {
  429. cout << "Age has to be between 14 - 100" << endl;
  430. system("pause");
  431. system("cls");
  432. enterMeasurements3(A);
  433. }
  434. else
  435. {
  436. return A;
  437. }
  438. return A;
  439. }
  440.  
  441.  
  442. void calculations() {
  443. double H, W, A;
  444. enterMeasurements(H);
  445. enterMeasurements2(W);
  446. enterMeasurements3(A);
  447. weight = W;
  448. height = H;
  449. age = A;
  450. bmi = W / (H / 100 * H / 100);
  451.  
  452. if (bmi < 18.5) {
  453. bmiCat = "Underweight";
  454. targetbmi = bmi + 2;
  455. }
  456. else if (bmi > 18.5 && bmi < 24.9) {
  457. bmiCat = "Normal weight";
  458. targetbmi = 22;
  459. }
  460. else if (bmi > 25 && bmi < 29.9) {
  461. bmiCat = "Overweight";
  462. targetbmi = bmi - 1;
  463. }
  464. else if (bmi > 30) {
  465. bmiCat = "Obese";
  466. targetbmi = bmi - 2;
  467. }
  468. cout << "\n" << "Your BMI is " << bmi << "kg/m" << char(253);
  469. cout << "\n" << "Your BMI catagory is " << bmiCat;
  470. cout << "\n" << "Your target BMI is " << targetbmi << "kg/m" << char(253) << endl;
  471. system("pause");
  472. calculations2();
  473. }
  474.  
  475.  
  476.  
  477. void calculations2() {
  478. int calc2options;
  479. do {
  480. for (int i = 0; i < 30; i++) { cout << "-"; }
  481. cout << "\n" << "Are you male or female?";
  482. cout << "\n" << "1. Male";
  483. cout << "\n" << "2. Female";
  484. cout << "\n" << "Please select an option: ";
  485. cin >> calc2options;
  486. if (cin.fail()) {
  487. cin.clear();
  488. cout << "Input Error, Numeric values only." << endl;
  489. system("pause");
  490. system("cls");
  491. menuSelections();
  492. }
  493. else {
  494. switch (calc2options) {
  495. case 1:
  496. option1();
  497. break;
  498. case 2:
  499. option2();
  500. break;
  501. case 0:
  502. exit(0);
  503. break;
  504. default:
  505. cout << "\n" << "Invalid Option Entered" << "\n";
  506. system("pause");
  507. system("cls");
  508. menuSelections();
  509. break;
  510. }
  511. }
  512. } while (calc2options != 1 && calc2options != 2 && calc2options != 0);
  513. }
  514.  
  515. void option1() {
  516. bmr = 88.362 + (13.397 * weight) + (4.799 * height) - (5.677 * age);
  517. cout << "\n" << "Your BMR is: " << bmr << endl;
  518. system("pause");
  519. kilo();
  520. }
  521.  
  522. void option2() {
  523. bmr = 447.593 + (9.247 * weight) + (3.098 * height) - (4.330 * age);
  524. cout << "\n" << "Your BMR is: " << bmr << endl;
  525. system("pause");
  526. kilo();
  527. }
  528.  
  529. void kilo() {
  530. int kiloOptions;
  531. do {
  532. cout << "\n" << "How much exercise do you do?";
  533. cout << "\n" << "1. Very little to no exercise";
  534. cout << "\n" << "2. Little exercise (1-2) days a week";
  535. cout << "\n" << "3. Medium exercise (3-5) days a week";
  536. cout << "\n" << "4. High exercise (4-6) days a week";
  537. cout << "\n" << "5. Intense exercise (7) days a week 2 times a day";
  538. cout << "\n" << "Please choose an option: ";
  539. cin >> kiloOptions;
  540. if (cin.fail()) {
  541. cin.clear();
  542. cout << "Input Error, Numeric values only. " << endl;
  543. system("pause");
  544. system("cls");
  545. menuSelections();
  546. }
  547. else {
  548. switch (kiloOptions) {
  549. case 1:
  550. kiloC = bmr * 1.2;
  551. cout << "\n" << "Returning to menu" << endl;
  552. menuSelections();
  553. break;
  554. case 2:
  555. kiloC = bmr * 1.375;
  556. cout << "\n" << "Returning to menu" << endl;
  557. menuSelections();
  558. break;
  559. case 3:
  560. kiloC = bmr * 1.55;
  561. cout << "\n" << "Returning to menu" << endl;
  562. menuSelections();
  563. break;
  564. case 4:
  565. kiloC = bmr * 1.725;
  566. cout << "\n" << "Returning to menu" << endl;
  567. menuSelections();
  568. break;
  569. case 5:
  570. kiloC = bmr * 1.9;
  571. cout << "\n" << "Returning to menu" << endl;
  572. menuSelections();
  573. break;
  574. case 0:
  575. exit(0);
  576. break;
  577. default:
  578. cout << "\n" << "Incorrect option entered" << "\n";
  579. system("pause");
  580. system("cls");
  581. menuSelections();
  582. break;
  583. }
  584. }
  585. } while (kiloOptions != 1 && kiloOptions != 2 && kiloOptions != 3 && kiloOptions != 4 && kiloOptions != 5 && kiloOptions != 0);
  586. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement