A real estate office manages 50 apartment units. When the rent is $550 per month
ID: 3803018 • Letter: A
Question
A real estate office manages 50 apartment units. When the rent is $550 per month, all units are occupied. However, for each $55 increase in rent per month, one unit becomes vacant. How many units should be rented to maximize the profit?
Write a VBA program that prompts the user to enter:
a. the rent to occupy all the units.
b. the increase in rent that results in a vacant unit.
c. you should display (clearly labeled) in a MsgBox the number of units rented to maximize profit and what the maximum profit at that number would be. You must use a FOR loop in this problem.
Please write in VBA code.
Explanation / Answer
( Rent within integer type limits and total value within long type limits )
Sub MaxProfit()
Dim NumOfApart As Integer
Dim i As Integer
Dim Rent As Integer
Dim RentInc As Integer
Dim TotalRent As Long
Dim ChangeRent As Long
NumOfApart = 50
Msg1 = "Enter rent to occupy all units"
Rent = InputBox(Msg1)
Msg2 = "Enter increase in rent that results in a vaccant unit"
RentInc = InputBox(Msg2)
For i = 1 To 50
TotalRent = CLng(Rent) * NumOfApart
Rent = Rent + RentInc
NumOfApart = NumOfApart - 1
ChangeRent = CLng(Rent) * NumOfApart
If (TotalRent > ChangeRent) Then
i = 51
NumOfApart = NumOfApart + 1
End If
Next i
MsgBox "The number of units rented to maximize profit is " & NumOfApart & " and the profit earned is " & TotalRent
End Sub
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.