Need help with Machine Problem!

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.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>


using namespace std;

int main()

{

	//////////////////////////////////////////////////////////////////////////////////////////

	double total_Units;
	double apt_Rent, maintenance_Cost, increase_in_Rent, rent_after_Increase, total_Maintenance;
	double max_Profit, profit, income, rent;
	double n;

	total_Units = 50.0;
	increase_in_Rent = 40.0;
	maintenance_Cost = 27.0;
	apt_Rent = 600.0; // only when all units are occupied
	max_Profit = 0.0;
	n = 50.0 - total_Units;
	rent_after_Increase = apt_Rent + increase_in_Rent;

	/////////////////////////////////////////////////////////////////////////////////////////

	cout << "Enter total number of units";

	cin >> total_Units;

	cout << "Enter cost in rent while all units are occupied";

	cin >> apt_Rent;

	cout << "Enter increase in rent per vacancy";

	cin >> increase_in_Rent;

	cout << "Enter the amount it costs to maintain a rented unit";

	cin >> rent_after_Increase;

	////////////////////////////////////////////////////////////////////////////////////////

	for (double units = 50.0; units > 0.0; units--, rent += increase_in_Rent)

	{

		income = total_Units * apt_Rent;

		total_Maintenance = total_Units * maintenance_Cost;

		profit = income - total_Maintenance;

		if (units == 50.0)

		{
			max_Profit = profit;
		}



		else if (profit > max_Profit)

		{
			max_Profit += profit;

			n = 50.0 - total_Units;
		}

		/////////////////////////////////////////////////////////////////////////////////////////

		cout << "Max number of profit that can be made is:";

		cout << n;

		cout << "\n";



		return 0;

	}
}

	///////////////////////////////////////////////////////////////////////////////////////////

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.
Last edited on
1
2
3
4
else if (profit > max_Profit)

		{
			max_Profit += profit;


Ouch!!

Too many rental firms doing this!
Topic archived. No new replies allowed.