Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Wonyoung Lee CPS 171 Machine Problem3.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- int main()
- {
- int userUnit = 0; // amount of unit user entered.
- int userIRent = 0; // cost of initial rent(fullly occupied).
- int userIncreFee = 0; // if one unit become vacant, the amount of fee increase.
- int userMaintain = 0; // amount of maintain fee per each occupied unit.
- int totalIncome = 0; // save total income
- int maximumCost = 0; // maximum cost
- int maxCostUnit = 0; // amount of unit when get maximum cost.
- cout << "Enter the total number of units: "; //get total units.
- cin >> userUnit;
- cout << "Enter the cost when your apartment fully occupied: "; //get initial cost.
- cin >> userIRent;
- cout << "Enter the increase in rent that results in a vacant unit: "; //get rate of increase fee.
- cin >> userIncreFee;
- cout << "Enter the amount to maintain fee for a occupied unit: "; //get occupied units maintain fee.
- cin >> userMaintain;
- int n = 0; // using for statement.
- for ( n = userUnit ; n > 0 ; n--)
- {
- totalIncome = userUnit * userIRent - userUnit * userMaintain;
- if (totalIncome > maximumCost) {
- maximumCost = totalIncome; //save maximum cost
- maxCostUnit = userUnit; //save amount of unit.
- }
- userUnit -= 1;
- userIRent += userIncreFee;
- }
- cout << endl << endl;
- cout << "If user rent " << maxCostUnit << " units user can get maximum cost " << maximumCost << " dollors." << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement