fork download
  1. //Zachary Abdollahi CS1A Chapter 3, P. 143, #3
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * COMPUTE TEST AVERAGE
  6.  * _____________________________________________________________________________
  7.  *
  8.  * This program asks the user for five test scores and calculates the average
  9.  * test score.
  10.  *
  11.  * Computation is based on the formula:
  12.  * Average = (Score1 + Score2 + Score3 + Score4 + Score5) / 5
  13.  * _____________________________________________________________________________
  14.  *
  15.  * INPUT
  16.  * score1, score2, score3, score4, score5 : Test scores
  17.  *
  18.  * OUTPUT
  19.  * average : Average test score
  20.  *
  21.  ******************************************************************************/
  22. #include <iostream>
  23. #include <iomanip>
  24. using namespace std;
  25. int main ()
  26. {
  27. float score1; //INPUT - First test score
  28. float score2; //INPUT - Second test score
  29. float score3; //INPUT - Third test score
  30. float score4; //INPUT - Fourth test score
  31. float score5; //INPUT - Fifth test score
  32. float average; //OUTPUT - Average test score
  33.  
  34. //
  35. // Get Input From User
  36. cout << "Enter the first test score: ";
  37. cin >> score1;
  38.  
  39. cout << "Enter the second test score: ";
  40. cin >> score2;
  41.  
  42. cout << "Enter the third test score: ";
  43. cin >> score3;
  44.  
  45. cout << "Enter the fourth test score: ";
  46. cin >> score4;
  47.  
  48. cout << "Enter the fifth test score: ";
  49. cin >> score5;
  50.  
  51. //
  52. // Compute Average Test Score
  53. average = (score1 + score2 + score3 + score4 + score5) / 5;
  54.  
  55. //
  56. // Output Result
  57. cout << fixed << setprecision(1);
  58. cout << "The average test score is " << average << endl;
  59.  
  60. return 0;
  61. }
Success #stdin #stdout 0s 5312KB
stdin
90
45
82
96
75
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 77.6