First of all, let's back up for a moment. I want to ask you about your array(s). What are you trying to store in your array(s)?
Right now it seems that you have 3 arrays (powerConsumptionJun, powerConsumptionAug and powerConsumptionJuly), and you look through each of them 1 time. That's essentially the same as having 3 non-array variables.
There are so many ways to do this better. I don't know what you have learned so far and what you are allowed to use in your assignment, but below are a few options.
One option would be a 12-element array powerConsumption[12] in which each element represents a specific month of the year. If you need to have the same information for a number of households, you could use a 2-dimensional array powerConsumption[NUM_HOUSEHOLDS][12]. Then you could loop through each household and check the month you need.
Rather than using 2-dimensional array, you could create a struct that contains 12 variables (or 7 if you only need Jun - Dec) like so:
1 2 3 4 5 6 7 8
|
struct ConsumptionByMonth
{
double jun;
double jul;
double aug;
...
double dec;
};
|
Then you could have a 1-dimensional array of these structs:
ConsumptionByMonth powerConsumption[NUM_HOUSEHOLDS]
Then loop through this array an pull out the value you need
powerConsumption[i].jun;
Better still than using arrays is to use a std::vector. For your simple program (I'm making some assumptions here) it will probably not matter a whole lot, but as you get more advanced in your programming, using standard template library (STL) classes will save you headaches and countless hours tracking down memory leaks. It's best to learn to use the STL as early as you can.
Now to your question. What you did will work if you also adjust top2 and top3 when you set top1. (When you set top1, the old top1 and top2 shift down to top2 and top3.) You might want to consider creating an array of top values rather than having individual variables here. too.
What I would do would be use a std::set or some other ordered data structure. As I read each value, I would throw it into the structure, and the largest values would be the 1st 3 in the structure when I was done. Or simpler yet, just throw all the values into a std::vector class (or array) and sort it. The first (or last) 3 elements will be the 3 largest.