fork download
  1. //Devin Scheu CS1A Chapter 2, P. 81, #5
  2. //
  3. /**************************************************************
  4. *
  5. * CALCULATE AVERAGE OF FIVE NUMBERS
  6. * ____________________________________________________________
  7. * This program calculates the average of five numbers by summing
  8. * them and dividing by the count of numbers.
  9. *
  10. * Computation is based on the formula:
  11. * average = sum / 5
  12. * ____________________________________________________________
  13. * INPUT
  14. * num1 : First number (as an integer: 28)
  15. * num2 : Second number (as an integer: 32)
  16. * num3 : Third number (as an integer: 37)
  17. * num4 : Fourth number (as an integer: 24)
  18. * num5 : Fifth number (as an integer: 33)
  19. *
  20. * PROCESSING
  21. * sum : The sum of num1, num2, num3, num4, and num5
  22. *
  23. * OUTPUT
  24. * average : The average of the five numbers
  25. *
  26. **************************************************************/
  27.  
  28. #include <iostream>
  29. #include <iomanip>
  30.  
  31. using namespace std;
  32.  
  33. int main () {
  34.  
  35. //Variable Declarations
  36. int num1; //INPUT - First number (as an integer: 28)
  37. int num2; //INPUT - Second number (as an integer: 32)
  38. int num3; //INPUT - Third number (as an integer: 37)
  39. int num4; //INPUT - Fourth number (as an integer: 24)
  40. int num5; //INPUT - Fifth number (as an integer: 33)
  41. int sum; //PROCESSING - The sum of num1, num2, num3, num4, and num5
  42. double average; //OUTPUT - The average of the five numbers
  43.  
  44. //Variable Initialization
  45. num1 = 28;
  46. num2 = 32;
  47. num3 = 37;
  48. num4 = 24;
  49. num5 = 33;
  50.  
  51. //Calculate Sum
  52. sum = num1 + num2 + num3 + num4 + num5;
  53.  
  54. //Calculate Average
  55. average = sum / 5.0;
  56.  
  57. //Output Result
  58. cout << fixed << setprecision(2) << "The average is: " << average << endl;
  59.  
  60. } //end of main()
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
The average is: 30.80