fork download
  1. //OrinTill Qimid CS1A Chapter 4, P. 294, 10
  2. //
  3. /**************************************************************
  4.  * Compute rainfall
  5.  *
  6.  * ____________________________________________________________
  7.  * This programs calculate the average rainfall per month
  8.  * ____________________________________________________________
  9.  * INPUT
  10.  * year : the amount of years program needs to calculate.
  11.  * OUTPUT
  12.  * total_month : The number of month
  13.  * total_rainfall : the total rainfall
  14.  * average_rain : average rainfall per month
  15.  **************************************************************/
  16. #include <iostream>
  17. #include <iomanip>
  18. #include <cmath>
  19. using namespace std;
  20.  
  21. int main()
  22. {
  23. float years,
  24. month,
  25. total_month,
  26. average_rain,
  27. rainfall,
  28. total_rainfall;
  29. cout<<"Please enter the amount of years"<<endl;
  30. cin >> years;
  31. for (float time = 1; time<= years; time++)
  32. {
  33. for (month = 1; month <= 12; month++)
  34. {
  35. rainfall;
  36. cout<<"please enter how much rainfall year "<<time<<", month 2"<< month<< endl;
  37. cin>> rainfall;
  38. total_rainfall=+rainfall;
  39. }
  40. total_month=+12;
  41. }
  42. average_rain=total_rainfall/total_month;
  43. cout << "\nNumber of months: " << total_month<< endl;
  44. cout << "Total inches of rainfall: " << total_rainfall << endl;
  45. cout << "Average rainfall per month: " << average_rain << " inches" << endl;
  46.  
  47.  
  48.  
  49.  
  50. return 0;
  51. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Please enter the amount of years

Number of months: 12
Total inches of rainfall: -1.52366e+09
Average rainfall per month: -1.26971e+08 inches