fork download
  1. //Sam Trivikraman CS1A Chapter 3, p.143, #3
  2. //
  3. /*
  4.  ******************************************************************************
  5. Calculate the average of five test scores
  6. _______________________________________________________________________________
  7. This program calculates the average from five test scores that the user inputs.
  8. _______________________________________________________________________________
  9. INPUT
  10.  
  11. scoreOne : the first test score (user input)
  12. scoreTwo : the second test score (user input)
  13. scoreThree : the third test score (user input)
  14. scoreFour : the fourth test score (user input)
  15. scoreFive : the fifth test score (user input)
  16.  
  17.  
  18. OUTPUT
  19. averageTestScore : the total average score from the five given test scores
  20. _______________________________________________________________________________
  21. *******************************************************************************
  22. */
  23. #include <iostream>
  24. #include <iomanip>
  25. using namespace std;
  26.  
  27. int main() {
  28.  
  29. float scoreOne; //INPUT the first test score
  30. float scoreTwo; //INPUT the second test score
  31. float scoreThree; //INPUT the third test score
  32. float scoreFour; //INPUT the fourth test score
  33. float scoreFive; //INPUT the fifth test score
  34. float averageTestScore; //OUTPUT the total average score from the five given test scores
  35.  
  36. //Gather test score inputs from user
  37. cout<< "Please enter five test scores separated by the ENTER key: " << endl;
  38. cin >> scoreOne;
  39. cin >> scoreTwo;
  40. cin >> scoreThree;
  41. cin >> scoreFour;
  42. cin >> scoreFive;
  43.  
  44. //Calculate the average test score
  45. averageTestScore = (scoreOne + scoreTwo + scoreThree + scoreFour + scoreFive) / 5;
  46.  
  47. //Set the precision to one decimal point
  48. cout << fixed << setprecision(1);
  49.  
  50. //Output result
  51. cout << "The average test score is: " << averageTestScore << endl;
  52. return 0;
  53. }
Success #stdin #stdout 0s 5300KB
stdin
2.5
8.3
6.0
5.8
7.6
stdout
Please enter five test scores separated by the ENTER key: 
The average test score is: 6.0