Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.07 KB | None | 0 0
  1.  
  2.  
  3. #include <iostream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. //Prototypes go here
  9. void calc(int rainfall[], int totalRainfall, double averageRainfall);
  10. void output(double averageRainfall, int totalRainfall, int rainHigh, int rainLow, string months[], string monthHigh, string monthLow);
  11.  
  12. int main()
  13. {
  14.     //Variables go here
  15.     string months[12] = {"January", "Feburary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
  16.     string monthHigh = " ";
  17.     string monthLow = " ";
  18.  
  19.     int rainfall[12] = {0};
  20.     int rainHigh = 0;
  21.     int rainLow = 500000;
  22.     int totalRainfall = 0;
  23.     double averageRainfall = 0;
  24.  
  25.     for(int i = 0; i < 12; i ++)
  26.     {
  27.         cout << "How much rain was collected in " << months[i] << "?" << endl;
  28.         cin >> rainfall[i];
  29.  
  30.         if(rainfall[i] > rainHigh)
  31.         {
  32.             rainHigh = rainfall[i];
  33.             monthHigh = months[i];
  34.         }
  35.         if(rainfall[i] < rainLow)
  36.         {
  37.             rainLow = rainfall[i];
  38.             monthLow = months[i];
  39.         }
  40.     }
  41.     calc(rainfall, totalRainfall, averageRainfall);
  42.     output(averageRainfall, totalRainfall, rainHigh, rainLow, months, monthHigh, monthLow);
  43.  
  44.  
  45.     system("Pause");
  46.     return 0;
  47. }
  48.  
  49. void calc(int rainfall[], int totalRainfall, double averageRainfall)
  50. {
  51.     int numberOfMonths = 12;
  52.  
  53.     for(int i = 0; i < 12; i ++)
  54.     {
  55.         totalRainfall = rainfall[i] + totalRainfall;
  56.     }
  57.     cout << totalRainfall << endl;
  58.     averageRainfall = totalRainfall / 12;
  59.     cout << averageRainfall << endl;
  60. }
  61.  
  62. void output(double averageRainfall, int totalRainfall, int rainHigh, int rainLow, string months[], string monthHigh, string monthLow)
  63. {
  64.     cout << endl;
  65.     cout << totalRainfall << endl;
  66.     cout << "Over the 12 months recorded the average rainfall for the year was " << averageRainfall << "." << endl << endl;
  67.  
  68.     cout << "Over the 12 month period the highest recorded rainfall is: " << rainHigh << endl << " which was during the month of " << monthHigh << "." << endl << endl;
  69.  
  70.     cout << "Over the 12 month period the lowest recorded rainfall is: " << rainLow << endl << "  which was during the month of" << monthLow << "." << endl << endl;
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement