# array stickler

hello everyone,thanks btseb,that worked a treat,some extra questions I have the same array of size (4, 2) filled with numbers, the 5 rows are items,the 3 columns are shops,and the numbers are the amount of each item sold in each shop.Now theres another array of prices,5 different prices for each of the 5 items.Now I want the maximum revenue item across all the shops,which shop,what item,and how many were sold.If thats not enough I also would like the total sales(revenue) of each of the items across all shops?
I promise that I will leave ye alone if ye help me on this one,all help will be deeply appreciated

• : hello everyone,thanks btseb,that worked a treat,some extra questions I have the same array of size (4, 2) filled with numbers, the 5 rows are items,the 3 columns are shops,and the numbers are the amount of each item sold in each shop.Now theres another array of prices,5 different prices for each of the 5 items.Now I want the maximum revenue item across all the shops,which shop,what item,and how many were sold.If thats not enough I also would like the total sales(revenue) of each of the items across all shops?
: I promise that I will leave ye alone if ye help me on this one,all help will be deeply appreciated
:
:

I replied to your other answer - there was a mistake in btseb's code. Please look there before continuing to the solution of this problem.

Now, for this problem:
Before I solve it for you, I'd just like to show you how I got the answer, so you actually learn from this instead of just copy-pasting the code. That is the kind of thing we like to do on this message board (I've been around this board for about 2 years).

We have:
Price for each item
Amount of items sold of each kind of item in every shop.

We want to know:
1)The item that gave us the most revenue (=i)
2)In which shop did it generate the most (=j)
3)How many were sold in that shop. (Using 1 and 2, the amount sold will be AmountSold(i,j))
4)How much did each item generate

Method:
The best way to do this is to do number 4 first - this will tell us which item generated the most (- compare the amount each item generated, the one that genereated the most will be our item). From there we will hae our "i". Then we can loop through each of the shops and find our j. And finally, we can, using our i and j, find the amount sol in that shop.

Now that I've explained the entire method, putting it together will be quite easy:
[code]
[green]'Let say our two arrays that were given are: AmountSold(4,2) and Price(4)
'I'm going to split up the code into steps. It won't be the most
'efficient code, but it will be easier to understand.[/green]
Dim TotalAmountGenerated(4), BestItemIndex, WhichShopIndex, HowMuch As Integer
Dim i, j As Integer
[green]'Calculate the total generated revenue for each item[/green]
For i = 0 To 4 [green]'For Each item[/green]
For j = 0 To 2 [green]'For each shop[/green]
TotalAmountGenerated(i) = AmountSold(i,j) * Price(i)
Next j
Next i
[green]'Find the item with the largest revenue[/green]
For i = 0 to 4
if TotalAmountGenerated(BestItemIndex) < TotalAmountGenerated(i) then BestItemIndex = i
Next i
[green]'Find which Shop it was sold in[/green]
For j = 0 To 2
if AmountSold(BestItemIndex,WhichShopIndex) < AmountSold(BestItemIndex,j) then WhichShopIndex = j
Next j
[green]'And HowMuch: [/green]
HowMuch = AmountSold(BestItemIndex,WhichShopIndex) * Price(BestItemIndex)
[/code]

I hope that helped. If you don't ask, you will never learn... Everyone had to start at one stage, and they did it by asking. So don't worry about posting questions.

Relman
• : : hello everyone,thanks btseb,that worked a treat,some extra questions I have the same array of size (4, 2) filled with numbers, the 5 rows are items,the 3 columns are shops,and the numbers are the amount of each item sold in each shop.Now theres another array of prices,5 different prices for each of the 5 items.Now I want the maximum revenue item across all the shops,which shop,what item,and how many were sold.If thats not enough I also would like the total sales(revenue) of each of the items across all shops?
: : I promise that I will leave ye alone if ye help me on this one,all help will be deeply appreciated
: :
: :
:
: I replied to your other answer - there was a mistake in btseb's code. Please look there before continuing to the solution of this problem.
:
: Now, for this problem:
: Before I solve it for you, I'd just like to show you how I got the answer, so you actually learn from this instead of just copy-pasting the code. That is the kind of thing we like to do on this message board (I've been around this board for about 2 years).
:
: We have:
: Price for each item
: Amount of items sold of each kind of item in every shop.
:
: We want to know:
: 1)The item that gave us the most revenue (=i)
: 2)In which shop did it generate the most (=j)
: 3)How many were sold in that shop. (Using 1 and 2, the amount sold will be AmountSold(i,j))
: 4)How much did each item generate
:
: Method:
: The best way to do this is to do number 4 first - this will tell us which item generated the most (- compare the amount each item generated, the one that genereated the most will be our item). From there we will hae our "i". Then we can loop through each of the shops and find our j. And finally, we can, using our i and j, find the amount sol in that shop.
:
: Now that I've explained the entire method, putting it together will be quite easy:
: [code]
: [green]'Let say our two arrays that were given are: AmountSold(4,2) and Price(4)
: 'I'm going to split up the code into steps. It won't be the most
: 'efficient code, but it will be easier to understand.[/green]
: Dim TotalAmountGenerated(4), BestItemIndex, WhichShopIndex, HowMuch As Integer
: Dim i, j As Integer
: [green]'Calculate the total generated revenue for each item[/green]
: For i = 0 To 4 [green]'For Each item[/green]
: For j = 0 To 2 [green]'For each shop[/green]
: TotalAmountGenerated(i) = AmountSold(i,j) * Price(i)
: Next j
: Next i
: [green]'Find the item with the largest revenue[/green]
: For i = 0 to 4
: if TotalAmountGenerated(BestItemIndex) < TotalAmountGenerated(i) then BestItemIndex = i
: Next i
: [green]'Find which Shop it was sold in[/green]
: For j = 0 To 2
: if AmountSold(BestItemIndex,WhichShopIndex) < AmountSold(BestItemIndex,j) then WhichShopIndex = j
: Next j
: [green]'And HowMuch: [/green]
: HowMuch = AmountSold(BestItemIndex,WhichShopIndex) * Price(BestItemIndex)
: [/code]
:
: I hope that helped. If you don't ask, you will never learn... Everyone had to start at one stage, and they did it by asking. So don't worry about posting questions.
:
: Relman
:

• That was spot on,perfect,might have another question for u soon,thanks once again,really appreciate it