Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<iomanip>
  4.  
  5. using namespace std;
  6.  
  7. double average(double *, int);
  8. int howManyA(double *, int);
  9.  
  10. int main()
  11. {
  12. // Variable declaration
  13. int size = 0;
  14. double average1 = 0;
  15. int countOfA = 0;
  16.  
  17. double *numbers = nullptr;
  18.  
  19. cout << fixed << setprecision(1);
  20.  
  21. //Ask user for how many test score they need and store it into size
  22. cout << "Enter number of test score: ";
  23. cin >> size;
  24.  
  25. cout << endl;
  26.  
  27. numbers = new double[size];
  28.  
  29. // A loop that will ask for score and inputs into array NUMBER until it is full depending on the size the user inouts
  30. for (int i = 0; i < size; i++)
  31. {
  32. cout << "Input score for " << (i + 1) << ": ";
  33. cin >> numbers[i];
  34. while (numbers[i] < 0)
  35. {
  36. cout << "Input valid score for " << (i + 1) << ": ";
  37. cin >> numbers[i];
  38. }
  39. }
  40.  
  41. //Function call to display the average
  42. average1 = average(numbers, size);
  43. cout << "\nThe average test score is " << average1 << endl;
  44.  
  45. //Function to display how many scores above 89
  46. countOfA = howManyA(numbers, size);
  47. cout << "There are " << countOfA << " scores above 89";
  48.  
  49. //This is used to delete the dynamic memeory created
  50. delete[] numbers;
  51.  
  52. system("pause");
  53. return 0;
  54. }
  55.  
  56. //Function that will get the array and user size, add up all the scores in a loop and divide by the size
  57. double average(double * score, int numScores)
  58. {
  59. double total = 0;
  60.  
  61. for (int i = 0; i < numScores; i++)
  62. {
  63. total += *(score + i);
  64. }
  65.  
  66. return (total / numScores);
  67. }
  68.  
  69. //Function that will loop through all the scores, and add one every time it comes across a score that is 90 and above
  70. int howManyA(double * score, int numScores)
  71. {
  72. int total = 0;
  73.  
  74. cout << numScores << endl;
  75.  
  76. for (int i = 0; i < numScores; i++)
  77. {
  78. //cout << score[i] << endl;
  79. cout << i << endl;
  80. if (score[i] >= 90)
  81. {
  82. total += 1;
  83. }
  84. return total;
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement