fork download
  1. //Castulo Jason Quintero CSC5 Chapter 3, P. 143, #4
  2. //
  3. /**************************************************************
  4.  *
  5.  * Compute Average Rainfall
  6.  * ____________________________________________________________
  7.  * This program compute average rainfall of the given months.
  8.  *
  9.  * Computation is based on the formula:
  10.  * sumRainInch = month1rain + month2rain + month3rain
  11.  * avgRainInch = sumRainInch/3
  12.  * ____________________________________________________________
  13.  * INPUT
  14.  * month1rain: Total Rainfall of that month
  15.  * month2rain: Total Rainfall of that month
  16.  * month3rain: Total Rainfall of that month
  17.  *
  18.  * OUTPUT
  19.  * avgRainInch : Average Rainfall of the the 3 months choosen
  20.  *
  21.  **************************************************************/
  22. #include <iostream>
  23. using namespace std;
  24. //
  25. int main() {
  26. string month1; //INPUT
  27. float month1rain;//INPUT
  28. string month2; //INPUT
  29. float month2rain;//INPUT
  30. string month3; //INPUT
  31. float month3rain; //INPUT
  32. float sumRainInch; // Variable
  33. float avgRainInch; // OUTPUT
  34.  
  35. // Input
  36. cout << "Choose any 3 months of the given year." <<endl;
  37. cout << "Enter the name of month, follow by the amount of rain (in inches) that fell during that month." << endl;
  38. cin >> month1;
  39. cin >> month1rain;
  40. cin >> month2;
  41. cin >> month2rain;
  42. cin >> month3;
  43. cin >> month3rain;
  44. //
  45. // Compute AVG Rainfall in inches
  46. sumRainInch = month1rain + month2rain + month3rain;
  47. avgRainInch = sumRainInch/3;
  48. // Output
  49. cout << "The average rainfall for " << month1 <<", "<< month2 << ", "
  50. << "and " << month3 << " was " << avgRainInch << " inches." << endl;
  51. //
  52. return 0;
  53. }
Success #stdin #stdout 0s 5304KB
stdin
September 1.67 
October 2.13
November 2.02
stdout
Choose any 3 months of the given year.
Enter the name of month, follow by the amount of rain (in inches) that fell during that month.
The average rainfall for September, October, and November was 1.94 inches.