fork download
  1. //Charlotte Davies-Kiernan CS1A Chapter 3 P.143 #3
  2. //
  3. /*****************************************************************************
  4.  *
  5.  * Compute Average Test Score
  6.  * ___________________________________________________________________________
  7.  * This program computes the average score of five test scores. Test scores are assumed to be in the range of 0 to 100.
  8.  *
  9.  * Using this formual:
  10.  * average= (first + second + third + fourth + fifth scores) / 5.0;
  11.  * ___________________________________________________________________________
  12.  * INPUT
  13.  * firstScore : score of the first test
  14.  * secondScore : score of the second test
  15.  * thirdScore : score of the third test
  16.  * fourthScore : score of the fourth test
  17.  * fifthScore : score of the fifth test
  18.  * OUTPUT
  19.  * average : average of the five test scores entered
  20.  ****************************************************************************/
  21. #include <iostream>
  22. #include <iomanip>
  23. using namespace std;
  24. int main()
  25. {
  26. float average; //OUTPUT - average of the five test scores entered
  27. float fifthScore; //INPUT - fifth test score
  28. float firstScore; //INPUT - first test score
  29. float fourthScore; //INPUT - fourth test score
  30. float secondScore; //INPUT - second test score
  31. float thirdScore; //INPUT - third test score
  32. //
  33. // Get five test scores
  34. cin >> firstScore;
  35. cin >> secondScore;
  36. cin >> thirdScore;
  37. cin >> fourthScore;
  38. cin >> fifthScore;
  39. //
  40. //Solve average
  41. if ((firstScore >= 0) && (firstScore <= 100))
  42. if ((secondScore >= 0) && (secondScore <= 100))
  43. if ((thirdScore >= 0) && (thirdScore <= 100))
  44. if ((fourthScore >= 0) && (fourthScore <= 100))
  45. if ((fifthScore >= 0) && (fifthScore <= 100))
  46. average = (firstScore + secondScore + thirdScore + fourthScore+ fifthScore) / 5.0;
  47. else
  48. cout << "INVALID SCORE" << endl;
  49. //
  50. //Display average
  51. cout << fixed << setprecision(1) << average;
  52. return 0;
  53. }
Success #stdin #stdout 0.01s 5316KB
stdin
175.3
65.0
92.4
85.4
76.3
stdout
0.0