Below is the exact description and requirements needed for my machine problem. Below I have attached the code for this problem that I have written up thus far. When I run the program I feel like I am not getting the correct Max Profit output so any corrections or pointers would be highly appreciated!
requirements:
Say a real estate office handles 50 apartment units. When the rent is $600 per month, all the units are occupied. However, for each $40 increase in rent, one unit becomes vacant. Moreover, each occupied unit requires an average of $27 per month for maintenance. How many units should be rented to maximize the profit?
Write a program that prompts the user to enter:
The total number of units.
The rent to occupy all the units.
The increase in rent that results in a vacant unit.
Amount to maintain a rented unit.
If I did it right you need to let 18 units go.
I get (573+18*40)*(50-18) = 41376
which I found with brute force by programming my calculator and doing a binary search by hand. (took about 30 seconds... try 0, try 49, try 25, home in on it)
this assumes that empty units have no maintenance cost.
What did you get?
you are using total units in your calculations but not all units are rented. That looks wrong.
you don't need to compute total maint; just sub maint cost from rent per unit cost once and use that (you can do it your way but it is extra code).
all you need is to find the max where:
base = initial rent - maintenance cost
max of units_rented*( base + increase*units_unrented)
so for your numbers.. if you wanted to look at 10 units empty...
40(this is num units rented) * ( (600-27) + 40(this is cost increase)*10 = 38920
which you can do by iteration over all the values as you did.