#include #include //for the "i/o manipulators" setw and setprecision #include using namespace std; //Interest is 6% annually. int main() { int nyears {0}; cout << "How many years? "; cin >> nyears; if (!cin) { cerr << "Bad input\n"; return EXIT_FAILURE; } if (nyears <= 0) { cerr << "The number of years must be positive.\n"; return EXIT_FAILURE; } double principal {0.00}; //start with this many dollars cout << "Starting with what principal? "; cin >> principal; if (!cin) { cerr << "Bad input\n"; return EXIT_FAILURE; } if (principal <= 0) { cerr << "Please provide a positive value.\n"; return EXIT_FAILURE; } double rate {0.00}; //this is the annual rate cout << "What is the annual rate in percent (e.g, 5)? "; cin >> rate; if (!cin) { cerr << "Could not perform input.\n"; return EXIT_FAILURE; } if (rate <=0) { cerr << "The interest rate must be positive.\n"; return EXIT_FAILURE; } //Each year, multiply the principal by the factor. const 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; }