fork download
  1. // Gage Alvarez CS1A Chapter 3 P.186, #4
  2.  
  3. /**************************************************************
  4.  *
  5.  * averaging rainfall per month
  6.  * ____________________________________________________________
  7.  * Description
  8.  * This program outputs the month and how many inches of rain fell each month
  9.  * ____________________________________________________________
  10.  * INPUT
  11.  * month1: the month that is first
  12.  * month2: the month that is second
  13.  * month3: month part 3
  14.  * month1Rain: the amount of rain in inches for the first month
  15.  * month2Rain: the amount of rain in inches for the second month
  16.  * month3Rain: the amount of rain in inches for the threed month
  17.  *
  18.  * OUTPUT
  19.  * the average amount of rain that fell for the three months
  20.  *
  21.  **************************************************************/
  22.  
  23.  
  24. #include <iostream>
  25. #include <string>
  26.  
  27. int main() {
  28. std::string month1;
  29. std::string month2;
  30. std::string month3;
  31. float month1Rain;
  32. float month2Rain;
  33. float month3Rain;
  34. float averagerain;
  35. std::cin >> month1 >> month2 >> month3;
  36. std::cin >> month1Rain >> month2Rain >> month3Rain;
  37.  
  38. averagerain = (1.0*month1Rain + month2Rain + month3Rain)/3;
  39.  
  40. std::cout << "The average amount of rain for months " << month1 << ", " << month2 << ", " << month3
  41. << " was " << averagerain << " inches ";
  42. return 0;
  43. }
Success #stdin #stdout 0s 5320KB
stdin
October November December 
16 5 12
stdout
The average amount of rain for months October, November, December was 11 inches