Ok so I have been beating my head against the wall for 3 days trying to get this program done and I am so close but stuck on one thing. The program is supposed to compile snowfall for 7 days then show a report, along with the high snowfall day and amount, and average snowfall over the period. I have it all except I can not figure out how to get the date that corresponds with the high snowfall total. If someone could please look this over and explain to me how to accomplish getting the date of the high snowfall I would be indebted.
Thanks,
Nate
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
int main()
{
const int numDays=7;
int date[numDays];
double snowFall[numDays];
int count;
double highestSnowFall;
int highestSnowDate;
double total = 0;
string Months[]={"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
int monthID;
cout<<"What month would you like to record snow totals for? (1-12)"<<endl;
cin>>monthID;
for(int index=0; index < numDays; index++)
{
cout<<"Enter the date of the snowfall "<<index+1<<endl;
cin>>date[index];
cout<<"Enter the amount of the snowfall."<<endl;
cin>>snowFall[index];
}
cout<<fixed<<showpoint<<setprecision(2);
cout<<"\n\n\tSnow report for "<<Months[monthID-1]<<endl;
cout<<"\t\t"<<endl;
if (snowFall[count] > highestSnowFall)
highestSnowFall = snowFall[count];
}
cout<<"\n\nThe highest snow fall total is "<<highestSnowFall<<" inches on the "<<endl;
cout<<"\nThe average snow fall is "<<total/numDays<<" inches"<<endl;
You can figure it out friend! Think about having a two variables, one that stores the current highest day, and another that holds the current highest snow fall. every time another day is entered, check its snowfall against the variable that you made to hold the highest snowfall. If the new value is bigger, then replace the day with the current day, and the highest snowfall with the current day's snowfall!
I added the highestSnowDate = date[count] like you said and it is giving me the final date that I put in. Say the highest snowfall total is on the 4th day of input I need the date to reflect that.
if (snowFall[count] > highestSnowFall)
highestSnowFall = snowFall[count];
highestSnowDate = date[count];
}
cout<<"\n\nThe highest snow fall total is "<<highestSnowFall<<" inches on the " <<highestSnowDate<<endl;
cout<<"\nThe average snow fall is "<<total/numDays<<" inches"<<endl;