fork download
  1. //Jacklyn Isordia CSC5 Chapter 3, P. 143, #03
  2. //
  3. /**************************************************************
  4.  *
  5.  * Calculate Average Test Score
  6.  * ____________________________________________________________
  7.  * This program asks the user to enter five test scores. The
  8.  * program calculates the average of the five scores and displays
  9.  * the result formatted in fixed-point notation with one decimal
  10.  * place.
  11.  *
  12.  * Computation is based on the formula:
  13.  * Average Score = (Score1 + Score2 + Score3 + Score4 + Score5) / 5
  14.  * ____________________________________________________________
  15.  * INPUT
  16.  * score1 : first test score
  17.  * score2 : second test score
  18.  * score3 : thirsd test score
  19.  * score4 : fourth test score
  20.  * score5 : fifth test score
  21.  *
  22.  * OUTPUT
  23.  * average : average of the five test scores
  24.  *
  25.  **************************************************************/
  26. #include <iostream>
  27. #include <iomanip>
  28. using namespace std;
  29.  
  30. int main()
  31. {
  32. float score1;
  33. float score2;
  34. float score3;
  35. float score4;
  36. float score5;
  37.  
  38. float average;
  39.  
  40. //
  41. // Input Values
  42. //
  43. cout << "Enter test score 1: " << endl;
  44. cin >> score1;
  45.  
  46. cout << "Enter test score 2: " << endl;
  47. cin >> score2;
  48.  
  49. cout << "Enter test score 3: " << endl;
  50. cin >> score3;
  51.  
  52. cout << "Enter test score 4: " << endl;
  53. cin >> score4;
  54.  
  55. cout << "Enter test score 5: " << endl;
  56. cin >> score5;
  57.  
  58. //
  59. // Compute Average
  60. //
  61. average = (score1 + score2 + score3 + score4 + score5) / 5;
  62.  
  63. //
  64. // Output Result
  65. //
  66. cout << fixed << setprecision(1);
  67. cout << " The average test score is " << average << endl;
  68.  
  69. return 0;
  70. }
Success #stdin #stdout 0.01s 5320KB
stdin
85
90
88
92
87
stdout
Enter test score 1: 
Enter test score 2: 
Enter test score 3: 
Enter test score 4: 
Enter test score 5: 
 The average test score is 88.4