fork download
  1. //Andres Guzman CSC5 Chapter 3, P. 143, #3
  2. //
  3. /**************************************************************
  4. *
  5. * FIND THE TEST AVERAGE
  6. * ____________________________________________________________
  7. * This program computes the average amongst 5 tests
  8. *
  9. * Computation is based on the formula:
  10. * sum = test1 + test2 + test3 +test4 + test5
  11. * average = sum / 5
  12. * ____________________________________________________________
  13. * INPUT
  14. * test1 :test score
  15. * test2 :test score
  16. * test3 :test score
  17. * test4 :test score
  18. * test5 :test score
  19. * OUTPUT
  20. * sum : total score of all tests
  21. * average = average of all tests
  22. **************************************************************/
  23. #include <iostream>
  24. #include <string>
  25. #include <iomanip>
  26. #include <cmath>
  27. using namespace std;
  28.  
  29. int main ()
  30. {
  31. //
  32. //Initializing variables for input
  33. int test1, test2, test3, test4, test5; //Input areas for each test score
  34. //
  35. //Output results
  36. cout << "The score from test 1: ";
  37. cin >> test1;
  38. cout << "\nThe score from test 2: ";
  39. cin >> test2;
  40. cout << "\nThe score from test 3: ";
  41. cin >> test3;
  42. cout << "\nThe score from test 4: ";
  43. cin >> test4;
  44. cout << "\nThe score from test 5: ";
  45. cin >> test5;
  46. //
  47. //Compute average formula
  48. int sum = test1 + test2 + test3 + test4 + test5;
  49. float average = sum / 5; // Output average of all test scores
  50. //
  51. //Output result
  52. cout << "\nThe average among the tests: ";
  53. cout << fixed << setprecision(1) << average << endl;
  54. return 0;
  55. }
Success #stdin #stdout 0s 5308KB
stdin
83 23 45 70 90
stdout
The score from test 1: 
The score from test 2: 
The score from test 3: 
The score from test 4: 
The score from test 5: 
The average among the tests: 62.0