fork(1) download
  1. //Xinnuo Wang CS1A chapter 2, P.81, # 4
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * COMPUTE THE AVERAGE OF VALUES
  6.  * _____________________________________________________________________________
  7.  * This program compute the average of a series of values, you add the values up
  8.  * and then divide the sum by the number of values. Write a program that stores
  9.  * the following values in five different variables: 28, 32, 37, 24, and 33. The
  10.  * program should first calculate the sum of these five variables and store the
  11.  * result in a separate variable named sum. Then, the program should divide the
  12.  * sum variable by 5 to get the average. Display the average on the screen.
  13.  *
  14.  * Computation is based on the formula:
  15.  * Sum = Numb1 + Numb2 + Numb3 + Numb4 + Numb5
  16.  * Average = Sum / 5
  17.  * _____________________________________________________________________________
  18.  * INPUT
  19.  * numb1 : The value of the first number
  20.  * numb2 : The value of the second number
  21.  * numb3 : The value of the third number
  22.  * numb4 : The value of the forth number
  23.  * numb5 : The value of the fivth number
  24.  *
  25.  * OUTPUT
  26.  * sum : The sum of the five numbers
  27.  * average value : Average of the five numbers
  28.  *
  29.  ******************************************************************************/
  30. #include <iostream>
  31. using namespace std;
  32.  
  33. int main()
  34. {
  35. int numb1; //INPUT - The value of the first number
  36. int numb2; //INPUT - The value of the second number
  37. int numb3; //INPUT - The value of the third number
  38. int numb4; //INPUT - The value of the forth number
  39. int numb5; //INPUT - The value of the fivth number
  40. int sum; //OUTPUT - The sum of the five numbers
  41. int averageValue; //OUTPUT - The average of the five numbers
  42. //
  43. // Initialize Program variables
  44. numb1 = 28;
  45. numb2 = 32;
  46. numb3 = 37;
  47. numb4 = 24;
  48. numb5 = 33;
  49. //
  50. // Compute the sum of the five numbers
  51. sum = numb1 + numb2 + numb3 + numb4 + numb5;
  52. //
  53. // Compute the average of the five numbers
  54. averageValue = sum/5;
  55. //
  56. //Output Result
  57. cout << "The average value of the five numbers is: "<< averageValue <<endl;
  58. return 0;
  59. }
Success #stdin #stdout 0s 5292KB
stdin
Standard input is empty
stdout
The average value of the five numbers is: 30