Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <limits>
  4. using namespace std;
  5.  
  6. string _MONTHS[12] = {"January", "Febuary", "March", "April", "May", "June",
  7.         "July","August", "September", "October", "November", "December"};
  8.  
  9. int main(int argc, char **argv){
  10.         float maxRainNum=0, minRainNum=-1;
  11.         int minRainMon=0, maxRainMon=0;
  12.         float total=0;
  13.         //Record the data
  14.         for(int i=0;i<12;i++){
  15.                 int recordTmp;
  16.                 // Get a non-negative rainfall amount
  17.                 do{
  18.                         cout << "Enter a non-negative amount of rainfall for " << _MONTHS[i] << ": ";
  19.                         cin >> recordTmp;
  20.                         //This is a trick required on some linux termianls.
  21.                         cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');
  22.                 } while (recordTmp < 0);
  23.  
  24.                 //If this is the largest we've seen yet (ties will be ignored)
  25.                 if(recordTmp > maxRainNum){
  26.                         maxRainNum=recordTmp;
  27.                         maxRainMon=i;
  28.                 }
  29.  
  30.                 // If this is the smallest we've seen yet (ties will be ignored)
  31.                 if(recordTmp < minRainNum || minRainNum==-1){
  32.                         minRainNum=recordTmp;
  33.                         minRainMon=i;
  34.                 }
  35.  
  36.                 // Add to the total
  37.                 total += recordTmp;
  38.         }
  39.  
  40.         //Display the data
  41.         cout << "Max month is " << _MONTHS[maxRainMon] << " with " << maxRainNum
  42.                 << endl;
  43.         cout << "Min month is " << _MONTHS[minRainMon] << " with " << minRainNum
  44.                 << endl;
  45.         cout << "The average rainfall is " << (total/12) << endl;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement