« April 2024 »
S M T W T F S
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
You are not logged in. Log in
Entries by Topic
All topics  «
Blog Tools
Edit your Blog
Build a Blog
RSS Feed
View Profile
Rainfall
Wednesday, 30 April 2008
Rainfall

#include <iostream>
#include <iomanip>
#include <cctype>
#include <vector>
using namespace std;

void Clear_Screen(void);
void Flush(void);
int main()
{
   bool notValid;
   float x, annualRain = 0, avgRain, lowRain, highRain;
   string month[12] = {"   January   :", "   February  :", "   March     :", "   April     :",
                       "   May       :", "   June      :", "   July      :", "   August    :",
                       "   September :", "   October   :", "   November  :", "   December  :"
                       };
   cout <<"Please enter the total rainfall for each month\n" << endl;
   vector<float> rainForMonth;
   vector<float>::iterator iter;
   for(int i=0; i<12; i++)
   {      
           do
           {                                                    //Validation for input
                 notValid=false;
                 cout <<"\nEnter rainfall for " <<  month[i] <<" ";
                 cin >> x;
                 if (x<0)
                 {
                    cout <<"Must be a positive number!\n";
                    notValid=true;
                 }
           }while (notValid);
      rainForMonth.push_back(x);
   }
   for(int i=0; i<rainForMonth.size(); i++)
   {
      annualRain = annualRain + rainForMonth.at(i);
   }
   Flush();
   cout << "\n\n   Press any key to display results" << endl;
   getchar();
   Clear_Screen();
   cout << "   Total rainfall for the year    : " << annualRain << endl;
   avgRain=(annualRain)/rainForMonth.size();
   cout << "   The average rainfall per month : " << avgRain << endl;
   iter = min_element(rainForMonth.begin(), rainForMonth.end());
   cout << "   The least amount of rainfall   : " << *iter << endl;
   iter = max_element(rainForMonth.begin(), rainForMonth.end());
   cout << "   The most amount of rainfall    : " << *iter << endl;
   cout << "\n\n   Thank you for using the program!" << endl;
   Flush();
   cout << "\n\n   Press any key to exit" << endl;
   getchar();
   return 0;
}

void Clear_Screen(void)
{
   #ifdef _WIN32
      system("cls");
   #else
      system("clear");
   #endif
}

void Flush(void)
{
   int ch;
   do
   {
      ch = getchar();
   }
   while (ch != EOF && ch != '\n');
   clearerr(stdin);
}


Posted by veronicak5678 at 9:00 PM EDT

Newer | Latest | Older