Re: How do I get the one part of the needed output for quarterly sales-statistics?
Have you looked at the printed output to see why the missing line is not being printed?
There is data for 4 quarters, why doesn't the data for one of the quarters get printed?
Look at the if statement that controls the printing. What values are required for the if statement to be true? How do the variables in the if statemennt get the correct values for the if to be true?
Re: How do I get the one part of the needed output for quarterly sales-statistics?
I answered each question one at a time.
Quote:
Have you looked at the printed output to see why the missing line is not being printed?
I have, and I believe it has to do with the way I declared highestQuart - as an accumulator, somehow - so I need help with that. Now I think I may have to make an if-statement for all of the quarters.
Quote:
There is data for 4 quarters, why doesn't the data for one of the quarters get printed?
I think data did not get printed for 4 quarters because there were always fewer numbers for it to print when it accumulated.
Quote:
Look at the if statement that controls the printing. What values are required for the if statement to be true?
It goes like this: If the last highest-quarter's number is equal to the current division's sales-figure then say, "Inside if-statement, quarters = # & divisions = #," so the values are highestQuart and salesFigures[quarters][divisions].
Quote:
How do the variables in the if-statement get the correct values for the if to be true?
The highestQuarter-variable was supposed to be replaced by another value, if you know what I mean, each time the second nested-for-loop passed for each quarter. As for the other variable, with each passing-loop, each quarter (all of them, 0-3) stays the same for six divisions (0-5) while each division-number is recieved by the second element-variable.
Re: How do I get the one part of the needed output for quarterly sales-statistics?
Quote:
I think data did not get printed for 4 quarters because there were always fewer numbers for it to print when it accumulated.
What does that mean? Each quarter has a highest sales figure amongst all the divisions. Why don't they all print?
Look at the data you printed out again. Why are you comparing the highest value from one quarter with the values for the next quarter? Should the values for each quarter be compared against only the other values for that same quarter and not against the values from preceding quarters?
Re: How do I get the one part of the needed output for quarterly sales-statistics?
Quote:
What does that mean? Each quarter has a highest sales figure amongst all the divisions. Why don't they all print?
I thought I made the highestQuart-variable an accumulator and now I realize that it does work as a non-accumulator, but I believe they don't all print because 3 more variables are needed to store the sales-figures in.
Quote:
Look at the data you printed out again. Why are you comparing the highest value from one quarter with the values for the next quarter? Should the values for each quarter be compared against only the other values for that same quarter and not against the values from preceding quarters?
As I did say before in this part of the thread, I believe I need 3 more variables to compare sales-figures to their associated ones within each quarter. By the way, I do believe each quarter should be compared against only others from the same quarter - not with ones from different quarters.
Re: How do I get the one part of the needed output for quarterly sales-statistics?
I solved the problem with something else to consider: one different array variable, and one new loop-control variable Here is how it works in code...
Code :
// Use these nested-loops to display the highest sales-division for a quarter.
for (int quarters = 0; quarters < QUARTERS; quarters++)
{
allDivisions++;
for (int divisions = 0; divisions < DIVISIONS; divisions++)
{
if (salesFigures[quarters][divisions] > highestQuart[allDivisions])
{
highestQuart[allDivisions] = salesFigures[quarters][divisions];
}
}
for (int divisions = 0; divisions < DIVISIONS; divisions++)
{
if (salesFigures[quarters][divisions] == highestQuart[allDivisions])
{
System.out.println("Inside if-statement, quarters = " + quarters + " & divisions = " + divisions);
}
}
}
...and this is what the computer's output was...
Inside if-statement, quarters = 0 & divisions = 2
Inside if-statement, quarters = 1 & divisions = 0
Inside if-statement, quarters = 1 & divisions = 4
Inside if-statement, quarters = 2 & divisions = 1
Inside if-statement, quarters = 3 & divisions = 2
...so as you can see, the computer gave all of the answers needed - even if some were equivalent. Now I only have to type up this kind of statement...
Code :
System.out.println("Highest sales-division for Quarter-" + (quarters + 1) + ": " + (divisions + 1));
...to get this kind of output.
Highest sales-division for Quarter-1: 1
Highest sales-division for Quarter-2: 5
Highest sales-division for Quarter-3: 6
Highest sales-division for Quarter-4: 4
Re: How do I get the one part of the needed output for quarterly sales-statistics?
Is the output correct now?
What if there are two divisions with the same sales? Have you tested that?
Re: How do I get the one part of the needed output for quarterly sales-statistics?
Quote:
Is the output correct now?
What if there are two divisions with the same sales? Have you tested that?
Yes, the output is correct, I have tested the second part too, and more than one division has appeared in a quarter. I somehow believe this works because of the way I setup the new array-variable - with 24 divisions for 4 quarters of 6 divisions, and 6 times 4 does equals 24.
Re: How do I get the one part of the needed output for quarterly sales-statistics?
A comment on your fix. The new code with the highestQuart array resets the value of highestQuart to zero every time the index to the array (allDivisoins) is incremented. 0 is the default contents of an int array.
A simpler solution would be to use the old version without the array and just set highestQuart to 0 when starting the search for the next division's highest value.