fork download
  1. //Ava Huntington CS1A Chapter 3 Homework P. 143, #3
  2. //
  3. /***************************************************************************
  4.  * AVERAGE FIVE TEST SCORES
  5.  * _________________________________________________________________________
  6.  * This programs takes the test scores on five given tests and finds the
  7.  * average of all five.
  8.  * _________________________________________________________________________
  9.  * INPUT
  10.  * test1: Score for given test #1
  11.  * test2: Score for given test #2
  12.  * test3: Score for given test #3
  13.  * test4: Score for given test #4
  14.  * test5: Score for given test #5
  15.  *
  16.  * OUTPUT
  17.  * avergeScore: Average of all five given test scores.
  18.  ***************************************************************************/
  19. #include <iostream>
  20. #include <iomanip>
  21. using namespace std;
  22.  
  23. int main()
  24. {
  25. float test1; //INPUT : Given score for test #1
  26. float test2; //INPUT : Given score for test #2
  27. float test3; //INPUT : Given score for test #3
  28. float test4; //INPUT : Given score for test #4
  29. float test5; //INPUT : Given score for test #5
  30. float averageScore; //OUTPUT : Average of all five given test scores
  31.  
  32. //Prompt to find score for test 1
  33. cout << "What is the score of test #1? "<<endl;
  34. cin >> test1;
  35.  
  36. //Prompt to find score for test 2
  37. cout << "What is the score of test #2? "<<endl;
  38. cin >> test2;
  39.  
  40. //Prompt to find score for test 3
  41. cout<<"What is the score of test #3? "<<endl;
  42. cin>> test3;
  43.  
  44. //Prompt to find score for test 4
  45. cout<<"What is the score of test #4? "<<endl;
  46. cin>> test4;
  47.  
  48. //Prompt to find score for test 5
  49. cout<<"What is the score of test #5? "<<endl;
  50. cin>> test5;
  51.  
  52. //Prompt to ensure answers are seperated by spaces
  53. cout<<"Please seperate answers with spaces. "<<endl;
  54.  
  55. //Equation to calculate the average of the five test scores
  56. averageScore = (test1+test2+test3+test4+test5)/5.0;
  57.  
  58. //Final output of the test score averages
  59. cout<< "The average test score for the five given tests is "
  60. <<setprecision(3)<<averageScore << ". "<<endl;
  61. return 0;
  62. }
Success #stdin #stdout 0.01s 5284KB
stdin
10 11 14 15 18
stdout
What is the score of test #1? 
What is the score of test #2? 
What is the score of test #3? 
What is the score of test #4? 
What is the score of test #5? 
Please seperate answers with spaces. 
The average test score for the five given tests is 13.6.