fork download
  1. // Nicolas Ruano CS1A Chapter 3 Pp.143-144 #4
  2. /*******************************************************************************
  3.  * CALCULATING THE AVERAGE RAINFALL
  4.  * ____________________________________________________________________________
  5.  * In this program, we check on the following months and their average of
  6.  * rainfall in each of the following different months provided below
  7.  * ___________________________________________________________________________
  8.  * INPUT
  9.  * month1: June
  10.  * month2: July
  11.  * month3: Augest
  12.  *
  13.  * rain1: June 5.2
  14.  * rain2: July 6.8
  15.  * rain3: Augest 8.2
  16.  * ____________________________________________________________________________
  17.  * PROCESS
  18.  * we get the results by solving out:
  19.  *
  20.  * Average = (rain1 + rain2 + rain3) / 3.0
  21.  * ____________________________________________________________________________
  22.  * OUTPUT
  23.  * The data being provided, based on the mathematical proceudre.
  24. *******************************************************************************/
  25. #include <iostream>
  26. #include <iomanip>
  27. #include <string>
  28. using namespace std;
  29.  
  30. int main() {
  31. string month1, month2, month3;
  32. double rain1, rain2, rain3, average;
  33.  
  34. // Ask user for inputs
  35. cout << "Enter the name of the first month: June";
  36. cin >> month1;
  37. cout << "Enter the rainfall (in inches) for June: 5.2" << month1 << ": ";
  38. cin >> rain1;
  39.  
  40. cout << "Enter the name of the second month: July";
  41. cin >> month2;
  42. cout << "Enter the rainfall (in inches) for July 6.8" << month2 << ": ";
  43. cin >> rain2;
  44.  
  45. cout << "Enter the name of the third month: Augest";
  46. cin >> month3;
  47. cout << "Enter the rainfall (in inches) for Augest: 8.2" << month3 << ": ";
  48. cin >> rain3;
  49.  
  50. // Calculate average rainfall
  51. average = (rain1 + rain2 + rain3) / 3.0;
  52.  
  53. // Display result
  54. cout << fixed << setprecision(2);
  55. cout << "\nThe average rainfall for June "
  56. << month1 << ", July" << month2 << ", and Augest" << month3
  57. << " is " << average << "6.73 inches." << endl;
  58.  
  59. return 0;
  60. }
  61.  
  62.  
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
Enter the name of the first month: JuneEnter the rainfall (in inches) for June: 5.2: Enter the name of the second month: JulyEnter the rainfall (in inches) for July 6.8: Enter the name of the third month: AugestEnter the rainfall (in inches) for Augest: 8.2: 
The average rainfall for June , July, and Augest is 0.006.73 inches.