fork download
  1. //Kanoa Holden CS1A Chapter 3, P. 143 Q#3
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * COMPUTE AVERAGE TEST SCORE
  6.  * _____________________________________________________________________________
  7.  * This program will calculate the average test score.
  8.  *
  9.  * Computation is based on the formula:
  10.  * average = score1 + score2 + score3 + score4 + score5 / 5.0
  11.  * _____________________________________________________________________________
  12.  * INPUT
  13.  * score1 : score of student 1
  14.  * score2 : score of student 2
  15.  * score3 : score of student 3
  16.  * score4 : score of student 4
  17.  * score5 : score of student 5
  18.  *
  19.  * OUTPUT
  20.  * average = average of students test scores
  21.  *
  22.  ******************************************************************************/
  23. #include <iostream>
  24. #include <iomanip>
  25.  
  26. using namespace std;
  27.  
  28. int main() {
  29. // Declare variables of test scores
  30. double score1, score2, score3, score4, score5;
  31.  
  32. // Ask the user to input five test scores
  33. cout << "\nEnter test score 1: ";
  34. cin >> score1;
  35.  
  36. cout << "\nEnter test score 2: ";
  37. cin >> score2;
  38.  
  39. cout << "\nEnter test score 3: ";
  40. cin >> score3;
  41.  
  42. cout << "\nEnter test score 4: ";
  43. cin >> score4;
  44.  
  45. cout << "\nEnter test score 5: ";
  46. cin >> score5;
  47.  
  48. // Calculate the average score
  49. double average = (score1 + score2 + score3 + score4 + score5) / 5.0;
  50.  
  51. // Display the average score
  52. cout << fixed << setprecision(1);
  53. cout << "\nThe average test score is: " << average << endl;
  54.  
  55. return 0;
  56. }
Success #stdin #stdout 0.01s 5284KB
stdin
37.8
45.2
22.3
12.2
35.4
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: 30.6