Advertisement
darkintegralgaming

mock exam code 1

Dec 4th, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6.  
  7. //Variables
  8. string names[5];
  9. names[0] = "Sam";
  10. names[1] = "Jack";
  11. names[2] = "Sue";
  12. names[3] = "Sue";
  13. names[4] = "Mary";
  14. bool keepGoing = true;
  15. int user;
  16. char answer = 'y';
  17.  
  18. //Title
  19. cout << "Find the employee app" << endl << endl;
  20.  
  21. //Traps them until they say no later
  22. while (keepGoing){
  23.  
  24. //Asks users could
  25. cout << "Please enter the employee code ";
  26. cin >> user;
  27.  
  28. //If user types correct values
  29. switch (user){
  30. case 1 : cout << " Employee Name: Sam" << endl;
  31. break;
  32.  
  33. case 2 : cout << " Employee Name: Jack" << endl;
  34. break;
  35.  
  36. case 3 : cout << " Employee Name: Sue" << endl;
  37. break;
  38.  
  39. case 4 : cout << " Employee Name: Sue" << endl;
  40. break;
  41.  
  42. case 5 : cout << " Employee Name: Mary" << endl;
  43. break;
  44.  
  45. default : cout << " ***Invalid code***" << endl << endl;
  46. }
  47.  
  48. //If user types in good values, this will help them escape the infinite loop. OTHERWISE IT WILL KEEP ASKING THEM FOR A CODE THANKS TO THE WHILE LOOP UP THERE
  49. if (user >= 1 && user <= 5){
  50.  
  51. //YOU ARE AN IDIOT while loop. Keeps asking them over and over until they type good answers YES and NO. YES and NO are coded to let them back into the while loop or end the program.
  52. while (answer != 'n'){
  53.  
  54. cout << endl << "Search again? "; //Ask user
  55. cin >> answer;
  56.  
  57. //DOOR! User wants to quit by typing no
  58. if (answer == 'n' || answer == 'N'){
  59.  
  60. //Breaks the keepGoing while loop, ending program
  61. keepGoing = false;
  62. cout << "Goodbye!";
  63. }
  64.  
  65. //DOOR! User wants go again, sending them back into the loop by break the YOU ARE AN IDIOT while loop
  66. if (answer == 'Y' || answer == 'y'){
  67. break;
  68. }
  69.  
  70. }
  71. }
  72.  
  73. }
  74.  
  75.  
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement