I have a couple classes under my belt and am learning while loops atm. I have an assignment taking input from a .txt and outputting various mins, maxes, averages. I have a system that works for finding all these, but I basically repeat it 5 times with different variables. I am wondering if there is a better way to go about it.
ex: Within my while eof loop.
1 2 3 4 5 6 7 8 9
if(lineCount == 0) {// ensure on first line of file.
max = x; // set x to max value
}
else {
if(x > max) {
max = x; // new max value
}
}
repeat 5x for different variables. Any suggestions on consolidation?
Well, you could just do the else part every time, and ensure max is initialized to 0 or a number definitely less than all the data you will be reading in.
The above suggestion is golden but if you are using classes to their full potential you could replace everything in the while loop with your class methods to clean up the variable declarations.
But I am curious as to what the 5 different variables are? Are you counting unsigned types as unique?
I am finding min of one column, max of another, average of another, highest delta between days in another. On some of these I need the dates of highs and lows. I assigned each day a variable, and then I have variable for each value and date that I need.
Yeah I may have overstated the functions part. We do know the items listed above and are just getting into the loops:) Thanks for the suggestions. I will start toying around and see if I can get it rolling.