fork download
  1. //Jeremy Huang CS1A Chapter 3, P. 143, #3
  2. //
  3. /**************************************************************
  4.  *
  5.  * CALCULATE TEST AVERAGE
  6.  * ____________________________________________________________
  7.  * This program calculates the test average of 5 tests based on
  8.  * the scores given in the input and averaging by dividing by
  9.  * 5.
  10.  * ____________________________________________________________
  11.  * INPUT
  12.  * test1 : Score for test 1
  13.  * test2 : Score for test 2
  14.  * test3 : Score for test 3
  15.  * test4 : Score for test 4
  16.  * test5 : Score for test 5
  17.  *
  18.  * OUTPUT
  19.  * testAverage : Average of the test scores
  20.  *
  21.  **************************************************************/
  22. #include <iostream>
  23. #include <iomanip>
  24. using namespace std;
  25.  
  26. int main() {
  27. float test1; //INPUT - Score for test 1
  28. float test2; //INPUT - Score for test 2
  29. float test3; //INPUT - Score for test 3
  30. float test4; //INPUT - Score for test 4
  31. float test5; //INPUT - Score for test 5
  32. float testAverage; //OUTPUT - Average of the test scores
  33.  
  34. //Prompt user for the score of Test 1
  35. cout<<"\nEnter the score for Test 1: ";
  36. cin>>test1;
  37.  
  38. //Prompt user for the score of Test 2
  39. cout<<"\nEnter the score for Test 2: ";
  40. cin>>test2;
  41.  
  42. //Prompt user for the score of Test 3
  43. cout<<"\nEnter the score for Test 3: ";
  44. cin>>test3;
  45.  
  46. //Prompt user for the score of Test 4
  47. cout<<"\nEnter the score for Test 4: ";
  48. cin>>test4;
  49.  
  50. //Prompt user for the score of Test 5
  51. cout<<"\nEnter the score for Test 5: ";
  52. cin>>test5;
  53.  
  54. //Calculate Test Average
  55. testAverage = (test1+test2+test3+test4+test5)/5;
  56.  
  57. //Output Result
  58. cout<<fixed<<showpoint<<setprecision(1);
  59. cout<<"\nThe average of the test scores is: "<<testAverage;
  60.  
  61. return 0;
  62. }
Success #stdin #stdout 0.01s 5292KB
stdin
70
80
75
90
100
stdout
Enter the score for Test 1: 
Enter the score for Test 2: 
Enter the score for Test 3: 
Enter the score for Test 4: 
Enter the score for Test 5: 
The average of the test scores is: 83.0