fork download
  1. //Matthew Santos CS1A Ch. 3, Pg. 143 , #3
  2. /***********************************************
  3.  *
  4.  * CALCULATE AVERAGE TEST SCORE
  5.  * _____________________________________________
  6.  * Asks for five test scores then displays the
  7.  * average.
  8.  * _____________________________________________
  9.  * INPUT
  10.  * testscore1 : score of test 1
  11.  * testscore2 : score of test 2
  12.  * testscore3 : score of test 3
  13.  * testscore4 : score of test 4
  14.  * testscore5 : score of test 5
  15.  * OUTPUT
  16.  * average : average of the five scores
  17.  *
  18.  ***********************************************/
  19. #include <iostream>
  20. #include <iomanip>
  21. using namespace std;
  22.  
  23. int main() {
  24.  
  25. //Define inputs and outputs
  26. float testscore1;
  27. float testscore2;
  28. float testscore3;
  29. float testscore4;
  30. float testscore5;
  31. float average;
  32.  
  33. //Acquire test scores
  34. cin >> testscore1 >> testscore2 >> testscore3 >> testscore4 >> testscore5;
  35.  
  36. //Compute average
  37. average = (testscore1 + testscore2 + testscore3 + testscore4 + testscore5) / 5;
  38.  
  39. //Display average
  40. cout << "Average: " << fixed << setprecision(1) << average << "%";
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 5328KB
stdin
50 89 70 35 100
stdout
Average: 68.8%