Solution to the Manhattan Island Problem
Solution to Programming Assignment
Program: Note that as the years move forward the principal gets really large and float no longer computes accurately - should be double.
/The Manhattan Island Problem
/* This program displays the value of the proposed investment of $24 in 1626, at an interest rate of .04, every 20 years. */
#include <iostream>
#include <iomanip>
using namespace std;
void main() {
float p, pzero, rate;
int i, year;
pzero = 24;
p = pzero;
rate = .04;
cout << setiosflags(ios::fixed | ios::showpoint)
<< setprecision (2);
cout << setw(20) << "YEAR" << setw(20) << "AMOUNT" << endl;
cout << " ------------------------------------------------------"
<< endl;
for (year=1626; year <=2006; year+=20) {
cout << setw(20) << year << setw(20) << p << endl;
for (i=1; i<=20; i++)
p = p + p*rate;
}
return;
Output: