Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. #include <iostream>
  2. #include "stdlib.h"
  3. using namespace std;
  4.  
  5. void runPassword();
  6. double enterTTNum(double &TT);
  7. void menuSelections();
  8. void forLoop();
  9. void precheckLoop();
  10. void postcheckLoop();
  11. void exit();
  12. int main(){
  13. runPassword();
  14. return 0;
  15. }
  16. void runPassword(){
  17. int correct_password = 1998;
  18. int password = 0;
  19. int attempt = 1;
  20. while (attempt <= 3){
  21. cout << "Enter your password to continue: ";
  22. cin >> password;
  23. attempt = attempt + 1;
  24. if (cin.fail()){
  25. cin.clear();
  26. //cin.ignore(INT_MAX, '\n'); Doesnt work.
  27. cout << "Input Error. Numeric values only!" << endl;
  28. runPassword();
  29. }
  30. else if (password != correct_password) {
  31. cout << "Incorrect password combination. Please Try again." << "\n";
  32. //runPassword();
  33. }
  34. else
  35. {
  36. break;
  37. }
  38. }
  39. if (attempt >= 3){
  40. if (password == correct_password){
  41. cout << "Access Granted." << endl;
  42. system("Pause");
  43. menuSelections();
  44. }
  45. else{
  46. exit(0);
  47. }
  48. }
  49. else{
  50. cout << "Access Granted." << endl;
  51. system("Pause");
  52. menuSelections();
  53. }
  54. }
  55. double enterTTNum(double &TT){
  56. double selection;
  57. for (int i = 0; i <30; i++){
  58. cout << "-";
  59. }
  60. cout <<"\n"<< "Enter your choice of the time table: " << endl;
  61. cin >> TT;
  62. if (cin.fail()){
  63. cin.clear();
  64. //cin.ignore(INT_MAX, '\n'
  65. cout <<"Input Error. Numeric values only." << endl;
  66. system("pause");
  67. system("cls");
  68. enterTTNum(TT);
  69. }
  70. else if (TT < 1 || TT>12){
  71. cout << "Number has to be between 1 and 12" << endl;
  72. system("pause");
  73. system("cls");
  74. enterTTNum(TT);
  75. }
  76. else{
  77. return TT;
  78. }
  79. return TT;
  80. }
  81. void menuSelections(){
  82. int MainMenuOptions;
  83. do{
  84. cout << "\n" << "| Menu Items |";
  85. cout << "\n" << "| |";
  86. cout << "\n" << "| 1. For Loop (Fixed Loop) |";
  87. cout << "\n" << "| 2. While (Pre-Check) |";
  88. cout << "\n" << "| 3. Do Loop (Post-Check) |";
  89. cout << "\n" << "| |";
  90. cout << "\n" << "| 0. Exit Program |";
  91. cout << "\n" << "| |";
  92. for (int i = 0; i < 30; ++i){
  93. cout << "-";
  94. }
  95. cout << "\n" << "Please select an option: ";
  96. cin >> MainMenuOptions;
  97. if (cin.fail()){
  98. cin.clear();
  99. //cin.ignore(INT_MAX, '\n'
  100. cout << "Input Error, Numeric values only." << endl;
  101. system("pause");
  102. system("cls");
  103. menuSelections();
  104. }
  105. else{
  106. switch (MainMenuOptions){
  107. case 1:
  108. forLoop();
  109. break;
  110. case 2:
  111. precheckLoop();
  112. break;
  113. case 3:
  114. postcheckLoop();
  115. break;
  116. case 0:
  117. exit();
  118. break;
  119. default:
  120. cout << "\n" << "Invalid Option entered" << "\n";
  121. system("pause");
  122. system("cls");
  123. menuSelections();
  124. break;
  125. }
  126. }
  127. } while (MainMenuOptions != 1 && MainMenuOptions != 2 && MainMenuOptions != 3 && MainMenuOptions !=0);
  128. }
  129. void forLoop(){
  130. int Answer;
  131. double TT = 0;
  132. enterTTNum(TT);
  133. for (int i = 1; i < 12; i++){
  134. Answer = TT * i;
  135. cout << TT << " * " << i << " = " << Answer << endl;
  136. }
  137. system("pause");
  138. exit();
  139. }
  140. void precheckLoop(){
  141. int Answer;
  142. double TT=0;
  143. enterTTNum(TT);
  144. int i = 0;
  145. while ( i < 12){
  146. i = i + 1;
  147. Answer + TT * i;
  148. cout << TT << " * " << i << " = " << Answer << endl;
  149. }
  150. system("pause");
  151. exit();
  152. }
  153. void postcheckLoop(){
  154. int Answer;
  155. double TT;
  156. enterTTNum(TT);
  157. int i = 0;
  158. do{
  159. i = i + 1;
  160. Answer = TT * i;
  161. cout << TT << " * " << i << " * " << Answer << endl;
  162. } while (i < 12);
  163. system("pause");
  164. exit();
  165. }
  166. void exit(){
  167. char choice;
  168. cout << "\n\n\n" << "Do you want to run the program again? (Y or N): ";
  169. cin >> choice;
  170. if (choice == 'Y' || choice == 'y'){
  171. system("cls");
  172. menuSelections();
  173. }
  174. else if (choice == 'N' || choice == 'n'){
  175. exit(0);
  176. }
  177. else{
  178. cout << "\n" << "Invalid letter. Only accept Y or N" << "\n";
  179. exit();
  180. }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement