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. int test1, test2, test3, test4, test5;
  32. //
  33. //Output results
  34. cout << "The score from test 1: ";
  35. cin >> test1;
  36. cout << "\nThe score from test 2: ";
  37. cin >> test2;
  38. cout << "\nThe score from test 3: ";
  39. cin >> test3;
  40. cout << "\nThe score from test 4: ";
  41. cin >> test4;
  42. cout << "\nThe score from test 5: ";
  43. cin >> test5;
  44. //
  45. //
  46. int sum = test1 + test2 + test3 + test4 + test5;
  47. float average = sum / 5;
  48. cout << "\nThe average amonst the tests: ";
  49. cout << fixed << setprecision(1) << average << endl;
  50. return 0;
  51. }
Success #stdin #stdout 0.01s 5324KB
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 amonst the tests: 62.0