#include #include //for the "i/o manipulators" setw and setprecision #include using namespace std; //Interest is 6% annually. int main() { double rate {0.0}; //start with this many dollars cout << "What is the interest rate?\n"; cin >> rate; if (!cin){ cerr << "That's not a valid value.\n"; return EXIT_FAILURE; } double factor {1.00 + .01 * rate}; double principal {0}; cout << "How much money are you starting with?\n"; cin >> principal; if (!cin) { cerr << "That's not a number!\n"; return EXIT_FAILURE; } if (principal <= 0) { cerr << "This value is not valid.\n"; return EXIT_FAILURE; } int year {0}; cout << "How many years are we looking at?\n"; cin >> year; if (!cin) { cerr << "You can't measure time with that.\n"; return EXIT_FAILURE; } if (year <=0) { cerr << "That's not a valid number of years.\n"; return EXIT_FAILURE; } if (year > 30) { cerr << "Reaches maturity at 30 years.\n"; return EXIT_FAILURE; } cout << "year principal\n"; //column headings cout << "-------------\n"; for (int year {1}; year <= 30; ++year) { principal *= 1.06; //means principal = principal * 1.06 cout << setw(4) << year << " $" << fixed << setprecision(2) << principal << "\n"; } return EXIT_SUCCESS; }