Having trouble with the last part of my array...

I've written the first 2 thirds of the program, but the final part seems to be escaping me.

I needed to make an array asking the user for 3 salesmen, and then ask them for quarterly earning for each salesman, before finally posting the total earned by each salesman. I got that part easily enough.

Now, though, I need to find who earned the most, per quarter, and post the best earner for each quarter.

I've been told to use if statements and for loops to find the answer, but whenever it outputs I always get "Best Earner for Q1 was [First Input Name] with 0 earnings.

Help, please?

My code for the final part is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
for (count2; count2 < QUARTERS; count2++)
        {
            highestSales = 0;

            cout << "The highest earner for Q" << count2 + 1;

            for (count1; count1 << SALES_BROS; count1++)
            {
                if (highestSales < salesEarned[count1][count2])
                    {
                        highestSales = salesEarned[count1][count2];
                        highestDude = count1;
                    }
            }

            cout << " was " << salesNames[highestDude] << " with " << highestSales << endl;

        }


QUARTERS is hard set to 4, and SALES_BROS is hard set to 3.
count 2 is supposed to be quarters, because I figured checking each quarter was better than checking the 1/2/3/4 quarters for each salesman and then comparing.
Last edited on
Your condition for ending the for loop, count1 << SALES_BROS , appears to be an instruction to left shift the value count1. That seems odd.

Last edited on
<< should be < on line 7.
Well...

Fixing that at least got the first Quarter to respond correctly, but all Quarters after that list the first Quarter's highest earner as winning with a total of 0 earned.
Wait!

Got it!

I wasn't resetting count1 correctly...

Thanks you, Moschops (and also Peter) haha.
Last edited on
Topic archived. No new replies allowed.