#include
#include
int year[5]; //stores five years entered by the user
int count ;
char choice; //stores date in 12 characters
float new_temp[5]; //stores 5 temperatures
float max , min , avg , total_temp , hi_year ,lo_year ;
struct date
{
char month[9];
int day;
};
date md;
//this function initializes all variable
// s to zero
void initialize()
{
clrscr(); //clears screen at program start
for(count=0;count<5;count++)
{
year[count]=0;
new_temp[count]=0;
}
choice='c';
max=0;
min=0;
total_temp=0;
avg=0;
} //end of initialize
//this function is used to determine max
// imum and minimum values for data entered
//
void max_and_min()
{
if(count==0) /*first data is taken as both highest and lowest for years and
temperature*/
{
min=new_temp[count];
lo_year=year[count];
max=new_temp[count];
hi_year=year[count];
}
if(new_temp[count] { min=new_temp[count]; lo_year=year[count]; //determines the year of lowest temperature } if(new_temp[count]>max) { max=new_temp[count]; hi_year=year[count]; //determines the year of highest temperature } } //end on max_and_min void input_and_process() //this function is used to take inputs { cout<<"\n\n\t\t\tCLIMATE ANALYSIS PROGRAM"; cout<<"\n\t\t****************************************"; cout<<"\n\n\nMonth and date : "; cin>>md.month>>md.day; for(count=0;count<5;count++) //takes input five times { cout<<"\n\nYear : "; cin>>year[count]; cout<<"Temperature : "; cin>>new_temp[count]; max_and_min(); //calls upon the max/min function total_temp=total_temp+new_temp[count]; //adds the temp inputs } avg=total_temp/5; //calculates the average temperature over the years } //end if input_and_result void output_results() /*this function outputs the inputs in organized form plus the calculated value*/ { clrscr(); cout<<"\n\t\t\tCLIMATE ANALYSIS PROGRAM"; cout<<"\n\t\t****************************************"; cout<<"\n\nDate : "< for(count=0;count<5;count++) cout<<"\n\n\tTemp : "< /* the above loop outputs all the five inputs one by one*/ cout<<"\n\n\n\t\t Maximum Temperature : "< cout<<"\n\n\t\t Minimum Temperature : "< cout<<"\n\n\t\t Average Temperature : "< } //end of output void main() { do { initialize(); input_and_process(); output_results(); cout<<"\n\n\nc...cont.q...quit"<<"\n\tEnter a choice : "; /*allows the user to rerun the program or to exit it*/ choice=getch(); } while(choice=='c' && choice!='q'); } //end of main