fork download
  1. //Devin Scheu CS1A Chapter 3, P. 143, #3
  2. //
  3. /**************************************************************
  4. *
  5. * CALCULATE AVERAGE TEST SCORE
  6. * ____________________________________________________________
  7. * This program calculates the average of five test scores
  8. * provided by the user and displays the result.
  9. *
  10. * Computation is based on the formula:
  11. * average = (score1 + score2 + score3 + score4 + score5) / 5
  12. * ____________________________________________________________
  13. * INPUT
  14. * score1 : First test score (as a double)
  15. * score2 : Second test score (as a double)
  16. * score3 : Third test score (as a double)
  17. * score4 : Fourth test score (as a double)
  18. * score5 : Fifth test score (as a double)
  19. *
  20. * PROCESSING
  21. * sum : The sum of the five test scores
  22. *
  23. * OUTPUT
  24. * average : The average of the five test scores
  25. *
  26. **************************************************************/
  27.  
  28. #include <iostream>
  29. #include <iomanip>
  30.  
  31. using namespace std;
  32.  
  33. int main () {
  34.  
  35. //Variable Declarations
  36. double score1; //INPUT - First test score (as a double)
  37. double score2; //INPUT - Second test score (as a double)
  38. double score3; //INPUT - Third test score (as a double)
  39. double score4; //INPUT - Fourth test score (as a double)
  40. double score5; //INPUT - Fifth test score (as a double)
  41. double sum; //PROCESSING - The sum of the five test scores
  42. double average; //OUTPUT - The average of the five test scores
  43.  
  44. //Prompt for Input
  45. cout << "Enter the first test score: ";
  46. cin >> score1;
  47. cout << "\nEnter the second test score: ";
  48. cin >> score2;
  49. cout << "\nEnter the third test score: ";
  50. cin >> score3;
  51. cout << "\nEnter the fourth test score: ";
  52. cin >> score4;
  53. cout << "\nEnter the fifth test score: ";
  54. cin >> score5;
  55.  
  56. //Calculate Sum
  57. sum = score1 + score2 + score3 + score4 + score5;
  58.  
  59. //Calculate Average
  60. average = sum / 5.0;
  61.  
  62. //Output Result
  63. cout << fixed << setprecision(1) << "\nThe average test score is: " << average << endl;
  64.  
  65. } //end of main()
Success #stdin #stdout 0s 5320KB
stdin
80
80
90
90
85
stdout
Enter the first test score: 
Enter the second test score: 
Enter the third test score: 
Enter the fourth test score: 
Enter the fifth test score: 
The average test score is: 85.0