fork download
  1. // Jeremy Huang CS1A Chapter 2, Pp. 81, #5
  2.  
  3. /*****************************************************************************
  4.  * CALCULATE AVERAGE
  5.  * ____________________________________________________________________________
  6.  * This program calculates the average of a set of values by finding their sum
  7.  * and dividing by the total number of values.
  8.  * ___________________________________________________________________________
  9.  * INPUT
  10.  * num1 : first number
  11.  * num2 : second number
  12.  * num3 : third number
  13.  * num4 : fourth number
  14.  * num5 : fifth number
  15.  *
  16.  * OUTPUT
  17.  * average : average of the five numbers inputted
  18.  *
  19.  * **************************************************************************/
  20.  
  21. #include <iostream>
  22. using namespace std;
  23.  
  24. int main() {
  25. //Declaring variables
  26. double num1 = 28;
  27. double num2 = 32;
  28. double num3 = 37;
  29. double num4 = 24;
  30. double num5 = 33;
  31.  
  32. //Computing sum and average
  33. double sum = num1+num2+num3+num4+num5;
  34. double average = sum/5;
  35.  
  36. //Output
  37. cout<<"Average: "<<average;
  38.  
  39. //End Program
  40. return 0;
  41. }
Success #stdin #stdout 0.01s 5328KB
stdin
Standard input is empty
stdout
Average: 30.8