Advertisement
Guest User

Untitled

a guest
Jan 11th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4. #include "stdlib.h"
  5. #include <iomanip>
  6. using namespace std;
  7. void runUsername();
  8. void runPassword();
  9. void mainMenu();
  10. void exit();
  11. void helpMenu();
  12. void exitHelp();
  13.  
  14.  
  15. int main() {
  16. runUsername();
  17. return 0;
  18. }
  19. void runUsername() {
  20. string correct_username = "username";
  21. string username;
  22. int attempt = 1;
  23. while (attempt <= 3) {
  24. cout << "Enter your username to continue: ";
  25. cin >> username;
  26. attempt = attempt + 1;
  27. if (cin.fail()) {
  28. cin.clear();
  29. cout << "Input Error. Numeric values only!" << endl;
  30. runUsername();
  31. }
  32. else if (username != correct_username) {
  33. cout << "Incorrect username. Please Try again." << "\n";
  34. }
  35. else
  36. {
  37. break;
  38. }
  39. }
  40. if (attempt >= 3) {
  41. if (username == correct_username) {
  42. cout << "Access Granted." << endl;
  43. runPassword();
  44. }
  45. else {
  46. exit(0);
  47. }
  48. }
  49. else {
  50. cout << "Access Granted." << endl;
  51. runPassword();
  52. }
  53. }
  54. void runPassword() {
  55. string correct_password = "password";
  56. string password;
  57. int attempt = 1;
  58. while (attempt <= 3) {
  59. cout << "Enter your password to continue: ";
  60. cin >> password;
  61. attempt = attempt + 1;
  62. if (cin.fail()) {
  63. cin.clear();
  64. cout << "Input Error. Numeric values only!" << endl;
  65. runPassword();
  66. }
  67. else if (password != correct_password) {
  68. cout << "Incorrect password combination. Please Try again." << "\n";
  69. }
  70. else
  71. {
  72. break;
  73. }
  74. }
  75. if (attempt >= 3) {
  76. if (password == correct_password) {
  77. cout << "Access Granted." << endl;
  78. mainMenu();
  79. }
  80. else {
  81. exit(0);
  82. }
  83. }
  84. else {
  85. cout << "Access Granted." << endl;
  86. mainMenu();
  87. }
  88. }
  89. void exit() {
  90. char choice;
  91. cout << "\n\n\n" << "Do you want to go back to the main menu? (Y or N): ";
  92. cin >> choice;
  93. if (choice == 'Y' || choice == 'y') {
  94. system("cls");
  95. mainMenu();
  96. }
  97. else if (choice == 'N' || choice == 'n') {
  98. exit(0);
  99. }
  100. else {
  101. cout << "\n" << "Invalid letter. Only accept Y or N" << "\n";
  102. exit();
  103. }
  104. }
  105. void mainMenu() {
  106. int MainMenuOptions;
  107. do {
  108. system("cls");
  109. for (int i = 0; i < 30; ++i) { cout << "-"; }
  110. cout << "\n" << "Main Menu";
  111. cout << "\n" << "";
  112. cout << "\n" << "1. Help Menu";
  113. cout << "\n" << "2. Customer Details";
  114. cout << "\n" << "3. Calculation Details";
  115. cout << "\n" << "4. Customer Profile";
  116. cout << "\n" << "";
  117. cout << "\n" << "0. Exit Program";
  118. cout << "\n" << "" << endl;
  119. for (int i = 0; i < 30; ++i) { cout << "-"; }
  120. cout << "\n" << "Please select an option: ";
  121. cin >> MainMenuOptions;
  122. if (cin.fail()) {
  123. cin.clear();
  124. cout << "Input Error, Numeric values only." << endl;
  125. system("pause");
  126. system("cls");
  127. mainMenu();
  128. }
  129. else {
  130. switch (MainMenuOptions) {
  131. case 1:
  132. helpMenu();
  133. break;
  134. case 2:
  135. customerDetails();
  136. break;
  137. case 3:
  138. cout << "Please die"; //calcDetails();
  139. break;
  140. case 4:
  141. customerProfile();
  142. break;
  143. case 0:
  144. exit();
  145. break;
  146. default:
  147. cout << "\n" << "Invalid Option entered" << "\n";
  148. system("pause");
  149. system("cls");
  150. mainMenu();
  151. break;
  152. }
  153. }
  154. } while (MainMenuOptions != 1 && MainMenuOptions != 2 && MainMenuOptions != 3 && MainMenuOptions != 0);
  155. }
  156. void helpMenu() {
  157. int helpMenuOptions;
  158. do {
  159. for (int i = 0; i < 32; ++i) { cout << "-"; }
  160. cout << "\n" << "Help Menu";
  161. cout << "\n" << "";
  162. cout << "\n" << "1. Question 1";
  163. cout << "\n" << "2. Question 2";
  164. cout << "\n" << "3. Question 3";
  165. cout << "\n" << "4. Question 4";
  166. cout << "\n" << "5. Question 5";
  167. cout << "\n" << "6. Question 6";
  168. cout << "\n" << "";
  169. cout << "\n" << "0. Exit Program";
  170. cout << "\n" << "" << endl;
  171. for (int i = 0; i < 32; ++i) { cout << "-"; }
  172. cout << "\n" << "Please select an option: ";
  173. cin >> helpMenuOptions;
  174. if (cin.fail()) {
  175. cin.clear();
  176. cout << "Input Error, Numeric values only." << endl;
  177. system("pause");
  178. system("cls");
  179. mainMenu();
  180. }
  181. else {
  182. switch (helpMenuOptions) {
  183. case 1:
  184. q1(); //change
  185. break;
  186. case 2:
  187. q2(); //change
  188. break;
  189. case 3:
  190. q3(); //change
  191. break;
  192. case 4:
  193. q4(); //change
  194. break;
  195. case 5:
  196. q5(); //change
  197. case 6:
  198. q6(); //change
  199. break;
  200. case 0:
  201. exit();
  202. break;
  203. default:
  204. cout << "\n" << "Invalid Option entered" << "\n";
  205. system("pause");
  206. system("cls");
  207. mainMenu();
  208. break;
  209. }
  210. }
  211. } while (helpMenuOptions != 1 && helpMenuOptions != 2 && helpMenuOptions != 3 && helpMenuOptions != 0);
  212. }
  213. void exitHelp() {
  214. char choice;
  215. cout << "\n\n\n" << "Would you like to go back to the help menu? (Y or N): ";
  216. cin >> choice;
  217. if (choice == 'Y' || choice == 'y') {
  218. system("cls");
  219. helpMenu();
  220. }
  221. else if (choice == 'N' || choice == 'n') {
  222. char choice;
  223. cout << "\n\n\n" << "Would you like to go back to the main menu? (Y or N)";
  224. cin >> choice;
  225. if (choice == 'Y' || choice == 'y') {
  226. system("cls");
  227. mainMenu();
  228. }
  229. else if (choice == 'N' || choice == 'n') {
  230. exit(0);
  231. }
  232. }
  233. else {
  234. cout << "\n" << "Invalid letter. Only accept Y or N" << "\n";
  235. exit();
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement