Advertisement
lwytop

Wonyoung Lee Machine Problem #4

Jun 17th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  1. // Wonyoung Lee CPS 171 Machine Problem3.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main()
  11. {
  12.     int userUnit = 0;       // amount of unit user entered.
  13.     int userIRent = 0;      // cost of initial rent(fullly occupied).
  14.     int userIncreFee = 0;   // if one unit become vacant, the amount of fee increase.
  15.     int userMaintain = 0;   // amount of maintain fee per each occupied unit.
  16.  
  17.     int totalIncome = 0;    // save total income
  18.     int maximumCost = 0;    // maximum cost
  19.     int maxCostUnit = 0;    // amount of unit when get maximum cost.
  20.    
  21.     cout << "Enter the total number of units: ";                            //get total units.
  22.     cin >> userUnit;
  23.  
  24.     cout << "Enter the cost when your apartment fully occupied: ";          //get initial cost.
  25.     cin >> userIRent;
  26.  
  27.     cout << "Enter the increase in rent that results in a vacant unit: ";   //get rate of increase fee.
  28.     cin >> userIncreFee;
  29.  
  30.     cout << "Enter the amount to maintain fee for a occupied unit: ";                   //get occupied units maintain fee.
  31.     cin >> userMaintain;
  32.  
  33.     int n = 0;              // using for statement.
  34.  
  35.  
  36.     for ( n = userUnit ; n > 0 ; n--)
  37.     {
  38.         totalIncome = userUnit * userIRent - userUnit * userMaintain;
  39.  
  40.         if (totalIncome > maximumCost) {
  41.             maximumCost = totalIncome;          //save maximum cost
  42.             maxCostUnit = userUnit;             //save amount of unit.
  43.         }
  44.  
  45.         userUnit -= 1;
  46.         userIRent += userIncreFee;
  47.     }
  48.  
  49.     cout << endl << endl;
  50.     cout << "If user rent " << maxCostUnit << " units user can get maximum cost " << maximumCost << " dollors." << endl;
  51.    
  52.  
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement