Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- //Prototypes go here
- void calc(int rainfall[], int totalRainfall, double averageRainfall);
- void output(double averageRainfall, int totalRainfall, int rainHigh, int rainLow, string months[], string monthHigh, string monthLow);
- int main()
- {
- //Variables go here
- string months[12] = {"January", "Feburary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
- string monthHigh = " ";
- string monthLow = " ";
- int rainfall[12] = {0};
- int rainHigh = 0;
- int rainLow = 500000;
- int totalRainfall = 0;
- double averageRainfall = 0;
- for(int i = 0; i < 12; i ++)
- {
- cout << "How much rain was collected in " << months[i] << "?" << endl;
- cin >> rainfall[i];
- if(rainfall[i] > rainHigh)
- {
- rainHigh = rainfall[i];
- monthHigh = months[i];
- }
- if(rainfall[i] < rainLow)
- {
- rainLow = rainfall[i];
- monthLow = months[i];
- }
- }
- calc(rainfall, totalRainfall, averageRainfall);
- output(averageRainfall, totalRainfall, rainHigh, rainLow, months, monthHigh, monthLow);
- system("Pause");
- return 0;
- }
- void calc(int rainfall[], int totalRainfall, double averageRainfall)
- {
- int numberOfMonths = 12;
- for(int i = 0; i < 12; i ++)
- {
- totalRainfall = rainfall[i] + totalRainfall;
- }
- cout << totalRainfall << endl;
- averageRainfall = totalRainfall / 12;
- cout << averageRainfall << endl;
- }
- void output(double averageRainfall, int totalRainfall, int rainHigh, int rainLow, string months[], string monthHigh, string monthLow)
- {
- cout << endl;
- cout << totalRainfall << endl;
- cout << "Over the 12 months recorded the average rainfall for the year was " << averageRainfall << "." << endl << endl;
- cout << "Over the 12 month period the highest recorded rainfall is: " << rainHigh << endl << " which was during the month of " << monthHigh << "." << endl << endl;
- cout << "Over the 12 month period the lowest recorded rainfall is: " << rainLow << endl << " which was during the month of" << monthLow << "." << endl << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement