Im trying to find a maximum profit for a apartment complex. I used a loop to find all the different profits, but I need to find the maximum value of profit. How would I be able to find the max profit ? Should I be using a loop or another way to do this ? Im still new to coding, help is very appreciated.
#include <iostream>
using namespace std;
int main()
{
// Containers for all variables
int units;
int rent;
int incrent;
int maintain;
int profit;
// User input
cout << "How many units are being rented: ";
cin >> units;
cout << "How much is rent for each occupied room: $";
cin >> rent;
cout << "How much will rent need to increase for someone to leave: $";
cin >> incrent;
cout << "How much money does it cost to maintain a occupied room: $";
cin >> maintain;
//cout << "At max units rented you make $" << units * rent - maintain << endl;
//Profit calculations
while(units >= 0)
{
cout << "While at " << units << " rented you make $" << (units * rent) - (maintain * units) << endl;
rent = rent + incrent;
units--;
}
Aucun commentaire:
Enregistrer un commentaire