fork download
  1. //OrinTill Qimid CS1A Chapter 4, P. 294, 4
  2. //
  3. /**************************************************************
  4.  * Calculate Rainfall
  5.  *
  6.  * ____________________________________________________________
  7.  * This program will display the highest and the lowest rain fall with the average rain fall
  8.  * ____________________________________________________________
  9.  * INPUT
  10.  * rainfall : rainfall per month
  11.  *
  12.  * OUTPUT
  13.  * highest : highest number of rain fall
  14.  * lowest : lowest number of rainfall
  15.  * Average : average number of rainfall
  16.  * total_rainfall : total number of rainfall
  17.  **************************************************************/
  18. #include <iostream>
  19. #include <iomanip>
  20. #include <cmath>
  21. using namespace std;
  22.  
  23.  
  24.  
  25. int main()
  26. {
  27. const int ARRAY_SIZE = 12;
  28. double rainfall[ARRAY_SIZE];
  29. float total_rainfall;
  30. float average;
  31. float highest;
  32. float lowest;
  33. lowest = 1000000000.0;
  34. highest = 0.0;
  35. total_rainfall = 0.0;
  36. for (int i = 0; i < 12; i++)
  37. {
  38. cout<<"Please enter the amount of rain fall for month "<<i+1<<endl;
  39. cin>>rainfall[i];
  40. total_rainfall +=rainfall[i];
  41. if (lowest > rainfall[i])
  42. {
  43. lowest = rainfall[i];
  44. }
  45. if (highest<rainfall[i])
  46. {
  47. highest = rainfall [i];
  48. }
  49.  
  50.  
  51. }
  52. average = total_rainfall/12;
  53. cout<<"the total amount of rainfall is "<<total_rainfall<<endl;
  54. cout<<"the average rainfall is "<<average<<" highest rainfall is "<<highest<<" lowest rainfall is "<<lowest<<endl;
  55. return 0;
  56. }
  57.  
  58.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty