Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <limits>
- using namespace std;
- string _MONTHS[12] = {"January", "Febuary", "March", "April", "May", "June",
- "July","August", "September", "October", "November", "December"};
- int main(int argc, char **argv){
- float maxRainNum=0, minRainNum=-1;
- int minRainMon=0, maxRainMon=0;
- float total=0;
- //Record the data
- for(int i=0;i<12;i++){
- int recordTmp;
- // Get a non-negative rainfall amount
- do{
- cout << "Enter a non-negative amount of rainfall for " << _MONTHS[i] << ": ";
- cin >> recordTmp;
- //This is a trick required on some linux termianls.
- cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');
- } while (recordTmp < 0);
- //If this is the largest we've seen yet (ties will be ignored)
- if(recordTmp > maxRainNum){
- maxRainNum=recordTmp;
- maxRainMon=i;
- }
- // If this is the smallest we've seen yet (ties will be ignored)
- if(recordTmp < minRainNum || minRainNum==-1){
- minRainNum=recordTmp;
- minRainMon=i;
- }
- // Add to the total
- total += recordTmp;
- }
- //Display the data
- cout << "Max month is " << _MONTHS[maxRainMon] << " with " << maxRainNum
- << endl;
- cout << "Min month is " << _MONTHS[minRainMon] << " with " << minRainNum
- << endl;
- cout << "The average rainfall is " << (total/12) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement