fork(1) download
  1. // Nicolas Ruano CS1A Chapter 3 Pp.143-144 #4
  2. /*******************************************************************************
  3.  * CALCULATING THE AVERAGE RAINFALL
  4.  * ____________________________________________________________________________
  5.  * In this program,
  6.  *
  7. *******************************************************************************/
  8. #include <iostream>
  9. #include <iomanip>
  10. #include <string>
  11. using namespace std;
  12.  
  13. int main() {
  14. string month1, month2, month3;
  15. double rain1, rain2, rain3, average;
  16.  
  17. // Ask user for inputs
  18. cout << "Enter the name of the first month: June";
  19. cin >> month1;
  20. cout << "Enter the rainfall (in inches) for June: 5.2" << month1 << ": ";
  21. cin >> rain1;
  22.  
  23. cout << "Enter the name of the second month: July";
  24. cin >> month2;
  25. cout << "Enter the rainfall (in inches) for July 6.8" << month2 << ": ";
  26. cin >> rain2;
  27.  
  28. cout << "Enter the name of the third month: Augest";
  29. cin >> month3;
  30. cout << "Enter the rainfall (in inches) for Augest: 8.2" << month3 << ": ";
  31. cin >> rain3;
  32.  
  33. // Calculate average rainfall
  34. average = (rain1 + rain2 + rain3) / 3.0;
  35.  
  36. // Display result
  37. cout << fixed << setprecision(2);
  38. cout << "\nThe average rainfall for June "
  39. << month1 << ", July" << month2 << ", and Augest" << month3
  40. << " is " << average << "6.73 inches." << endl;
  41.  
  42. return 0;
  43. }
  44.  
  45.  
Success #stdin #stdout 0.01s 5320KB
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.