fork download
  1. //Andrew Alspaugh CS1A Chapter 3, P. 145. #3
  2. //
  3. /******************************************************************************************
  4.  *
  5.  * Calculate Test Average to 1 Fixed Point
  6.  *_________________________________________________________________________________________
  7.  * This program calculates and displays the average of 5 test scores
  8.  * ________________________________________________________________________________________
  9.  * INPUT:
  10.  * Score1 //Test score
  11.  * Score2 //Test score
  12.  * Score3 //Test score
  13.  * Score4 //Test score
  14.  * Score5 //Test score
  15.  *
  16.  * OUTPUT:
  17.  * AverageScore //Average score
  18.  * ***************************************************************************************/
  19.  
  20. #include <iostream>
  21. #include <iomanip>
  22. using namespace std;
  23. int main()
  24. {
  25.  
  26. //Input test scores
  27. float Score1; //Input - Test Score
  28. float Score2; //Input - Test Score
  29. float Score3; //Input - Test Score
  30. float Score4; //Input - Test Score
  31. float Score5; //Input - Test Score
  32. int TotalTests; //Input - Amount of Tests
  33. TotalTests = 5;
  34. //Declare scope of Average
  35. float AverageScore; //Output - Average score
  36.  
  37.  
  38. //Input Scores
  39. cout << "Enter test 1 score" << endl;
  40. cin >> Score1;
  41.  
  42. cout << "Enter test 2 score" << endl;
  43. cin >> Score2;
  44.  
  45. cout << "Enter test 3 score" << endl;
  46. cin >> Score3;
  47.  
  48. cout << "Enter test 4 score" << endl;
  49. cin >> Score4;
  50.  
  51. cout << "Enter test 5 score" << endl;
  52. cin >> Score5;
  53.  
  54. //Process for Average
  55. AverageScore = (Score1 + Score2 + Score3 + Score4 + Score5)/ TotalTests;
  56.  
  57. //Output Average
  58. cout << fixed << setprecision(1);
  59. cout << "Average Test Score is " << AverageScore;
  60. return 0;
  61. }
Success #stdin #stdout 0.01s 5288KB
stdin
100
90
80
95
50
stdout
Enter test 1 score
Enter test 2 score
Enter test 3 score
Enter test 4 score
Enter test 5 score
Average Test Score is 83.0