C++

closed account (2E1qDjzh)
//
// main.cpp
// CPS Machine Problems
//
// Created by Babafemi Omole on 2/25/18.
// Copyright © 2018 Babafemi Omole. All rights reserved.
//
/*
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?

profit = (600 * 50) - ( 27 * 50)

*/

#include <fstream>
#include <iomanip>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <cmath>
#include <ctime>

using namespace std;

int main()
{

int rentbase, rentincr, rentper, income, numapts, expsper, expense, profit, maxprofit, maxoccupancy, occupancy, maxrentper;
rentbase = 600;
rentincr = 40;
numapts = 50;
expsper = 27;

maxprofit = -1;
maxoccupancy = -1;
maxrentper = -1;

rentper = rentbase;
occupancy = 50;
while (occupancy > 0)
{
income = rentper * occupancy;
expense = expsper * occupancy;
profit = income - expense;

cout << occupancy << rentper << profit;
if (maxprofit < profit)
{
maxprofit = profit;
maxoccupancy = occupancy;
maxrentper = rentper;

rentper = rentper + rentincr;
occupancy = occupancy - 1;

cout << maxoccupancy << maxrentper << maxprofit;
}
}
return 0;

}


Help output is wrong Help please due tn
Topic archived. No new replies allowed.