Advertisement
Guest User

Untitled

a guest
Jan 11th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.01 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include "stdlib.h"
  4. #include <string>
  5. #include <iomanip>
  6. #include <conio.h>
  7.  
  8. using namespace std;
  9.  
  10.  
  11. void runUsername();
  12. void runPassword();
  13. void menuSelections();
  14. void helpMenu();
  15. void customerDetails();
  16. void MainExit();
  17. void HelpExit();
  18. int gymid, tele;
  19. string name, address, email;
  20.  
  21. int main()
  22. {
  23. runUsername();
  24. return 0;
  25. }
  26.  
  27. void runUsername()
  28. {
  29. int correct_username = 1990;
  30. int username = 0;
  31. int attempt = 1;
  32.  
  33. while (attempt <= 3) {
  34. cout << "Enter your username: ";
  35. cin >> username;
  36. attempt = attempt + 1;
  37.  
  38. if (cin.fail())
  39. {
  40. cin.clear();
  41. cin.ignore(INT_MAX, '\n');
  42. cout << "Input Error. Numeric values only" << endl;
  43. runUsername();
  44. }
  45. else if (username != correct_username) {
  46. cout << "Incorrect password combination. Please try again." << "\n";
  47. runUsername();
  48. }
  49. else
  50. {
  51. break;
  52. }
  53. }
  54. if (attempt >= 3)
  55. {
  56. if (username == correct_username)
  57. {
  58. cout << "Access granted." << endl;
  59. system("Pause");
  60. runPassword();
  61. }
  62. else
  63. {
  64. exit(0);
  65. }
  66. }
  67. else
  68. {
  69. cout << "Access granted." << endl;
  70. system("Pause");
  71. runPassword();
  72. }
  73. }
  74.  
  75. void runPassword()
  76. {
  77. int correct_password = 1998;
  78. int password = 0;
  79. int attempt = 1;
  80.  
  81. while (attempt <= 3) {
  82. cout << "Enter your password: ";
  83. cin >> password;
  84. attempt = attempt + 1;
  85.  
  86. if (cin.fail())
  87. {
  88. cin.clear();
  89. cin.ignore(INT_MAX, '\n');
  90. cout << "Input Error. Numeric values only" << endl;
  91. runPassword();
  92. }
  93. else if (password != correct_password) {
  94. cout << "Incorrect password combination. Please try again." << "\n";
  95. //runPassword();
  96. }
  97. else
  98. {
  99. break;
  100. }
  101. }
  102. if (attempt >= 3)
  103. {
  104. if (password == correct_password)
  105. {
  106. cout << "Access granted." << endl;
  107. system("Pause");
  108. menuSelections();
  109. }
  110. else
  111. {
  112. exit(0);
  113. }
  114. }
  115. else
  116. {
  117. cout << "Access granted." << endl;
  118. system("Pause");
  119. menuSelections();
  120. }
  121. }
  122.  
  123. void menuSelections()
  124. {
  125. int MainMenuOptions;
  126. //do-while loop starts here.that display menu again and again until user select to exit program
  127. do
  128. {
  129. cout << "\n" << "| Menu Items |";
  130. cout << "\n" << "| |";
  131. cout << "\n" << "| 1. Help Menu |";
  132. cout << "\n" << "| 2. Customer Details |";
  133. cout << "\n" << "| 3. Do Loop (Post Check) |";
  134. cout << "\n" << "| |";
  135. cout << "\n" << "| 0. Exit program |";
  136. cout << "\n" << "| |" << "\n";
  137.  
  138. for (int i = 0; i < 30; ++i)
  139. {
  140. cout << "-";
  141. }
  142. //Prompting user to enter an option according to menu
  143. cout << "\n" << "Please select an option : ";
  144. cin >> MainMenuOptions; // taking option value as input and saving in variable "option"
  145. if (cin.fail())
  146. {
  147. cin.clear();
  148. cin.ignore(INT_MAX, '\n');
  149. cout << "Input Error. Numeric values only" << endl;
  150. system("pause");
  151. system("cls");
  152. menuSelections();
  153. }
  154. else
  155. {
  156. switch (MainMenuOptions)
  157. {
  158. case 1:
  159. helpMenu();
  160. break;
  161. case 2:
  162. customerDetails();
  163. break;
  164. case 3:
  165. break;
  166. case 0:
  167. break;
  168. default:
  169. cout << "\n" << "Invalid Option entered" << "\n";
  170. system("pause");
  171. system("cls");
  172. menuSelections();
  173. break;
  174. }
  175. }
  176. } while (MainMenuOptions != 1 && MainMenuOptions != 2 && MainMenuOptions != 3 && MainMenuOptions != 0);
  177. }
  178.  
  179. void helpMenu()
  180. {
  181. int helpMenu;
  182.  
  183. do
  184. {
  185. system("cls");
  186. cout << "\n" << " Help Menu Items ";
  187. cout << "\n" << " ";
  188. cout << "\n" << " 1. How to calculate BMR? ";
  189. cout << "\n" << " 2. How to calculate BMI? ";
  190. cout << "\n" << " 3. How to calculate kilocalories? ";
  191. cout << "\n" << " 4. How to calculate calories? ";
  192. cout << "\n" << " 5. Why customer details are needed? ";
  193. cout << "\n" << " 6. Edit this? ";
  194. cout << "\n" << " " << endl;
  195. cout << "\n" << " 0. Exit";
  196.  
  197. for (int i = 0; i < 30; ++i)
  198. {
  199. cout << "-";
  200. }
  201.  
  202. cout << "\n" << "Please select an option :";
  203. cin >> helpMenu;
  204. if (cin.fail())
  205. {
  206. cin.clear();
  207.  
  208. cout << "Input Error. Numeric values only" << endl;
  209. system("pause");
  210. system("cls");
  211. menuSelections();
  212. }
  213. else
  214. {
  215. switch (helpMenu)
  216. {
  217. case 1:
  218. system("cls");
  219. 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;
  220. system("pause");
  221. //HelpExit();
  222. break;
  223. case 2:
  224. system("cls");
  225. 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;
  226. system("pause");
  227. //HelpExit();
  228. break;
  229. case 3:
  230. system("cls");
  231. cout << "\n\n" << "To calculate kilocalories you have to use this formula" << endl;
  232. system("pause");
  233. //HelpExit();
  234. case 4:
  235. system("cls");
  236. cout << "\n\n" << "To calculate calories you have to use this formula" << endl;
  237. system("pause");
  238. //HelpExit();
  239. case 5:
  240. system("cls");
  241. cout << "\n\n" << "You're required to pay 20% VAT" << endl;
  242. system("pause");
  243. //HelpExit();
  244. case 6:
  245. system("cls");
  246. cout << "\n\n" << "You're required to pay 20% VAT" << endl;
  247. system("pause");
  248. //HelpExit();
  249. case 0:
  250. system("cls");
  251. HelpExit();
  252. break;
  253. default:
  254. system("cls");
  255. cout << "\n" << "Invalid Option entered" << "\n";
  256. system("pause");
  257. system("cls");
  258. menuSelections();
  259. break;
  260. }
  261. }
  262. } while (helpMenu != 1 && helpMenu != 2 && helpMenu != 3 && helpMenu != 0);
  263. }
  264.  
  265. void customerDetails() {
  266. for (int i = 0; i < 32; ++i) { cout << "-"; }
  267. cout << "\n" << "Customer Details" << endl;
  268. for (int i = 0; i < 32; ++i) { cout << "-"; }
  269. cout << "\n" << "Please enter your gym id: ";
  270. cin >> gymid;
  271. cout << "\n" << "Please enter your name: ";
  272. cin >> name;
  273. cout << "\n" << "Please enter your phone number: ";
  274. cin >> tele;
  275. cout << "\n" << "Please enter your email address: ";
  276. cin >> email;
  277. cout << "\n" << "Please enter your address: ";
  278. cin >> address;
  279.  
  280. system("pause");
  281. system("cls");
  282. menuSelections();
  283. }
  284.  
  285. void customerProfile() {
  286.  
  287.  
  288.  
  289.  
  290. }
  291.  
  292. void MainExit() {
  293. char choice;
  294. cout << "\n\n\n" << "Do you want to go back to the main menu (y or n):";
  295. cin >> choice;
  296. if (choice == 'Y' || choice == 'y') {
  297. system("cls");
  298. menuSelections();
  299. }
  300. else if (choice == 'N' || choice == 'n') {
  301. exit(0);
  302. }
  303. else {
  304. cout << "\n" << "Invalid letter.Only accept Y or N";
  305. exit(0);
  306. }
  307. }
  308. void HelpExit() {
  309. char choice;
  310. cout << "\n\n\n" << "Do you want to go back to the help menu (y or n):";
  311. cin >> choice;
  312. if (choice == 'Y' || choice == 'y') {
  313. system("cls");
  314. helpMenu();
  315. }
  316. else if (choice == 'N' || choice == 'n') {
  317. MainExit();
  318. }
  319. else {
  320. cout << "\n" << "Invalid letter.Only accept Y or N";
  321. exit(0);
  322. }
  323. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement