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.
  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. average = (firstScore + secondScore + thirdScore + fourthScore+ fifthScore) / 5;
  42. //
  43. //Display average
  44. cout << fixed << setprecision(1) << average;
  45. return 0;
  46. }
Success #stdin #stdout 0.01s 5320KB
stdin
75.3
65.0
92.4
85.4
76.3
stdout
78.9