Problems sorting arrays

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;

for(int index=0; index < numDays; index++)
{

cout<<Months[monthID-1]<<" "<<date[index]<<"\t\t Snowfall "<<snowFall[index]<<endl;
}

highestSnowFall=snowFall[0];


for(int count=0; count < numDays; count++)
{
total+=snowFall[count];

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;

system("pause");
return 0;
}
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!

Programming is fun =]
Last edited on
1
2
3
4
if (snowFall[count] > highestSnowFall) {
    highestSnowFall = snowFall[count];
    highestSnowDate = date[count];
}
Well I have tried both or your recommendations, and It still isn't doing what I need it to do. Any other ideas?
What did you do, whad did you get and what did you want. My solution is working for me.
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.
it is giving me the final date that I put in
Did you miss braces after if startement? Show your modified code.
//Week 5 Lab 5
//Snow Fall Program
//Nathan Smith

#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;

for(int index=0; index < numDays; index++)
{

cout<<Months[monthID-1]<<" "<<date[index]<<"\t\t Snowfall "<<snowFall[index]<<endl;
}

highestSnowFall=snowFall[0];


for(int count=0; count < numDays; count++)
{
total+=snowFall[count];

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;

system("pause");
return 0;
}
MiiNiPaa i did miss the brackets. You are a lifesaver. Thankyou for all of you help.
Topic archived. No new replies allowed.