Advertisement
darkintegralgaming

mock exam code 2

Dec 4th, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. //Variables
  7. int a;
  8. int b;
  9. int c;
  10. int max;
  11. double mean;
  12. int min;
  13. int array[3];
  14. bool play = true;
  15. char answer;
  16.  
  17. //Title
  18. cout << "Integer Analysis App"<< endl << endl;
  19.  
  20. //Traps them forever until they say no
  21. while (play){
  22.  
  23. //Asks user for numbers
  24. cout << "Please enter the following...." << endl;
  25.  
  26. //Gets info, with some redudant code
  27. cout << " Integer 1: ";
  28. cin >> a;
  29. array[0] = a;
  30.  
  31. cout << " Integer 2: ";
  32. cin >> b;
  33. array[1] = b;
  34.  
  35. cout << " Integer 3: ";
  36. cin >> c;
  37. cout << endl;
  38. array[2] = c;
  39.  
  40. //Calculates the mean
  41. mean = (a + b + c) / 3;
  42.  
  43. //Sets min and max to the first number the user typed in.
  44. min = array[0];
  45. max = array[0];
  46.  
  47. //Checks for min and max
  48. for (int i = 0; i < 3; i++){
  49.  
  50. //Downgrades the min value if it find a smaller number
  51. if (min > array[i])
  52. min = array[i];
  53.  
  54.  
  55. //Upgrades the max value if it finds a bigger number
  56. if (max < array[i])
  57. max = array[i];
  58. }
  59.  
  60. //Prints results
  61. cout << "Analysis Results" << endl;
  62. cout << "Max: " << max << endl;
  63. cout << "Min: " << min << endl;
  64. cout << "Mean: " << mean << endl<< endl;
  65.  
  66. //Traps user if they type dumb stuff, looping them over in this mini loop. Good answers will free them, sending the the beginning of the program or ending it
  67. while (answer !='y' || answer != 'Y'){
  68.  
  69. //Gets users response
  70. cout << "Play again? ";
  71. cin >> answer;
  72. cout << endl;
  73.  
  74. //Frees the user and send them back to begining of the main program while loop
  75. if (answer =='y' || answer == 'Y')
  76. break;
  77.  
  78. //Ends the program by breaking the main while loop
  79. if (answer == 'n' || answer == 'N')
  80. play = false;
  81.  
  82. //Breaks the dumb question check while loop. The program will end because we set play to false
  83. if (answer == 'n' || answer == 'N')
  84. break;
  85. }
  86. }
  87. cout << "Good bye!";
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement