I am trying to write simple program using ONLY for loop (if then statement is allowed i think) And I am having trouble getting the highest snow date “calculated” from a bunch of user inputs.
This program writes user input amount of snow that fell on a number of days to a text file. I am supposed to also list the highest snow amount that fell, but don’t (?) know how to do it in the for loop.
for (dayNumber = 1; dayNumber <= numOfSnowDays; dayNumber++)
{
mostSnowDay = dayNumber;
cout << "Day number: " << dayNumber << endl;
cout << "Enter amount of snow: " << endl;
cin >> amtOfSnow;
totalSnow = totalSnow + amtOfSnow;
outFile << setfill(' ') << setw(15) << dayNumber << setw(25) << setprecision(2) << amtOfSnow << endl;
if ( dayNumber == 1 )
{
mostSnowDay = dayNumber;
}
else if ( amtOfSnow < mostSnowDay )
{
//dont know what to put here or even if this is right.
}
};
You need some extra variables there:
EDIT: Credit to Dan F. Remove the
mostSnowDay = dayNumber;instruction at the beginning of the loop, it will re-initialize your variable each time the loop enters.