fork download
  1. //Zachary Abdollahi CS1A Chapter 2, P. 81, #5
  2. //
  3. /****************************************************************************
  4.  *
  5.  * COMPUTE AVERAGE OF VALUES
  6.  * __________________________________________________________________________
  7.  * This program stores five integer values in separate variables,
  8.  * calculates their sum, and then calculates and displays the average.
  9.  *
  10.  * Computation is based on the formulas:
  11.  * Sum = val1 + val2 + val3 + val4 + val5
  12.  * Average = Sum / 5.0
  13.  * __________________________________________________________________________
  14.  * INPUT
  15.  * val1 : First integer value (28)
  16.  * val2 : Second integer value (32)
  17.  * val3 : Third integer value (37)
  18.  * val4 : Fourth integer value (24)
  19.  * val5 : Fifth integer value (33)
  20.  *
  21.  * OUTPUT
  22.  * sum : Total sum of the five values
  23.  * average : Average of the five values
  24.  *
  25.  **************************************************************************/
  26. #include <iostream>
  27. #include <iomanip>
  28. using namespace std;
  29.  
  30. int main()
  31. {
  32. float val1; //INPUT - First integer value
  33. float val2; //INPUT - Second integer value
  34. float val3; //INPUT - Third integer value
  35. float val4; //INPUT - Fourth integer value
  36. float val5; //INPUT - Fifth integer value
  37. float sum; //OUTPUT - Total sum of all values
  38. float average; //OUTPUT - Average of all values
  39.  
  40. // Initialize Program Variables
  41. val1 = 28;
  42. val2 = 32;
  43. val3 = 37;
  44. val4 = 24;
  45. val5 = 33;
  46.  
  47. // Compute Sum and Average
  48. sum = val1 + val2 + val3 + val4 + val5;
  49. average = sum / 5.0;
  50.  
  51. // Output Result
  52. cout << "The sum of the values is: " << sum << endl;
  53. cout << "The average of the values is: " << average << endl;
  54.  
  55. return 0;
  56. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
The sum of the values is: 154
The average of the values is: 30.8