HAYD1979

03-01-2012, 07:39 PM

Could someone possibly give me some pointers as to what i am missing in the top two functions below? I am supposed to create function where demand is calculated first and then used to perform the second calculation called "Profit". The "demand" calculation is supposed to be a part of the "profit" function, as i understand it. Only problem is i have no idea how to get it to work.

The third function, at the bottom, actually works fine. So i am a bit amazed that i can't get the top ones to work as they seem a lot simpler to me. :help

Option Explicit

Function demand(alpha, beta, gamma, price, adv)

Dim demand

demand = alpha * (price ^ beta) * (adv ^ gamma)

End Function

Function Profit(alpha, beta, gamma, cost, price, adv)

Profit = (price - cost) * demand(alpha, beta, gamma, price, adv) - adv

End Function

Function Opt_Price(alpha, beta, gamma, cost, adv)

Dim price, max_profit, price_start

price_start = 10

max_profit = Profit(alpha, beta, gamma, cost, price_start, adv)

For price = 10 To 100 Step 1

If max_profit < Profit(alpha, beta, gamma, cost, price, adv) Then

max_profit = Profit(alpha, beta, gamma, cost, price, adv)

Opt_Price = price

End If

Next price

End Function

The third function, at the bottom, actually works fine. So i am a bit amazed that i can't get the top ones to work as they seem a lot simpler to me. :help

Option Explicit

Function demand(alpha, beta, gamma, price, adv)

Dim demand

demand = alpha * (price ^ beta) * (adv ^ gamma)

End Function

Function Profit(alpha, beta, gamma, cost, price, adv)

Profit = (price - cost) * demand(alpha, beta, gamma, price, adv) - adv

End Function

Function Opt_Price(alpha, beta, gamma, cost, adv)

Dim price, max_profit, price_start

price_start = 10

max_profit = Profit(alpha, beta, gamma, cost, price_start, adv)

For price = 10 To 100 Step 1

If max_profit < Profit(alpha, beta, gamma, cost, price, adv) Then

max_profit = Profit(alpha, beta, gamma, cost, price, adv)

Opt_Price = price

End If

Next price

End Function