#include #include //for the "i/o manipulators" setw and setprecision #include using namespace std; int main() { cout << "Please enter the starting principal and then press RETURN. "; double principal {0.00}; cin >> principal; if (!cin) { cerr<< "Sorry, that wasn't an acceptable number.\n"; return EXIT_FAILURE; } if (principal <= 0){ cerr << " Sorry, the prinicipal must be positive.\n"; return EXIT_FAILURE; } cout <<"For how many years? "; int nyears {0}; cin >> nyears; if (!cin) { cerr << "Sorry that wasn't a number.\n"; return EXIT_FAILURE; } if (nyears <=0) { cerr << "Sorry, the number of years must be positive.\n"; return EXIT_FAILURE; } cout << "What is the annual interest rate in percent (e.g., 6)? "; double rate {0.00}; cin >> rate; if (!cin) { cerr << "Sorry, that wasn't a number.\n"; return EXIT_FAILURE; } if (rate <=0) { cerr << "Sorry, the interest rate must be positive.\n"; return EXIT_FAILURE; } double factor { 1.00 + .01 * rate}; cout << "year principal\n" //column headings << "---- ---------\n"; for (int year {1}; year <= nyears; ++year) { principal *= factor; //means principal = principal * factor cout << " " setw(2) << year << " $" << fixed << setprecision(2) << principal << "\n"; } return EXIT_SUCCESS; } //Also make sure the rate is a reasonable(e.g. positive) number. //Each year, multiply the principal by the following factor. //For example, if rate is 6, the factor will be 1.06 double factor rate {1.00+01* rate};