fork download
  1. // Cenyao Huang CS1A Chapter 3, P. 143, #3
  2.  
  3. /************************************************************************
  4. * COMPUTE TEST AVERAGE
  5. * This program computes the average score of five tests.
  6. *
  7. * This program uses the formula:
  8. * averageScore = (score1 + score2 + score3 + score4 + score5)/5
  9. *
  10. * Input
  11. * score1 : the score of the first test
  12. * score2 : the score of the second test
  13. * score3 : the score of the third test
  14. * score4 : the score of the fourth test
  15. * score5 : the score of the fifth test
  16. *
  17. * Output
  18. * averageScore : the average score of five tests
  19. *
  20. ************************************************************************/
  21.  
  22. #include <iostream>
  23. #include <string>
  24. #include <iomanip>
  25. using namespace std;
  26.  
  27. int main() {
  28. float score1, score2, score3, score4, score5, average; // assign data type to variable
  29. cout << "Please provide five test scores: " << endl; // prompt to enter in data
  30. cin >> score1 >> score2 >> score3 >> score4 >> score5; // reads scores from keyboard
  31.  
  32. average = (score1 + score2 + score3 + score4 + score5)/5; // calculates average
  33. cout << "the average is: " << fixed << setprecision(1) << average << endl; // displays average
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5316KB
stdin
1.5 2.5 1.0 1.0 3.0
stdout
Please provide five test scores: 
the average is: 1.8