Suppose that the rent for an apartment is $1000 per month this year and increases 3% every year. Write a C++ program that computes the rent in five years and the total rent for one year starting five years from now
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double rent_per_month = 1000;
double increase = 0.03;
double total = 0;
int n=5;
for (int i=0; i<n; i++) {
total += 12*rent_per_month;
rent_per_month *= 1 + increase;
}
cout << fixed << setprecision(2) << "The total rent for "
<< n << " yeas will be $" << total << endl;
cout << "The moth rent after " << n << " years from now "
<< "will be $" << rent_per_month;
return 0;
}
Comments
Leave a comment