fork download
  1. // Marvyn De La Torre CS1A Chapter 3, P.143, #4
  2.  
  3. /*************************************************************
  4. // Calculate Average Rainfall
  5. //
  6. // This program displays the average rainfall for three months.
  7. //
  8. // Input:
  9. // Names of three months
  10. // Rainfall amounts for three months
  11. //
  12. // Output:
  13. // Average rainfall for the three months
  14. *************************************************************/
  15.  
  16. #include <iostream>
  17. #include <iomanip>
  18. #include <string>
  19. using namespace std;
  20.  
  21. int main()
  22. {
  23. string month1;
  24. string month2;
  25. string month3;
  26. double rain1;
  27. double rain2;
  28. double rain3;
  29. double average;
  30.  
  31. cin >> month1;
  32. cin >> rain1;
  33. cin >> month2;
  34. cin >> rain2;
  35. cin >> month3;
  36. cin >> rain3;
  37.  
  38. average = (rain1 + rain2 + rain3) / 3;
  39.  
  40. cout << fixed << showpoint << setprecision(2);
  41. cout << "The average rainfall for " << month1 << ", "
  42. << month2 << ", and " << month3 << " is "
  43. << average << " inches.";
  44.  
  45. return 0;
  46. }
Success #stdin #stdout 0s 5320KB
stdin
June
5
July
7
August
8
stdout
The average rainfall for June, July, and August is 6.67 inches.