#include #include //for the "i/o manipulators" setw and setprecision #include using namespace std; //Principal, interest rate, and years are inputted by the user. int main() { double principal {1000.00}; //start with this many dollars cout << "What is the principal?\n"; cin >> principal; //user inputs the starting principal amount if (!cin){ cerr << "Sorry, that is not a valid number.\n"; return EXIT_FAILURE; //user must input a valid number } int nyears {0}; cout << "How many years?\n"; cin >> nyears; //user inputs the number of years if (!cin){ cerr << "Sorry, that is not a valid number.\n"; return EXIT_FAILURE; //user must input a valid number } if (nyears < 1){ cerr << "Sorry, you must input at least 1 year.\n"; return EXIT_FAILURE; //user must input a positive number } double rate; cout << "What is the interest rate? Input a whole number for the percent.\n"; cin >> rate; //user inputs the interest rate if (!cin){ cerr << "Sorry, that is not a valid number.\n"; return EXIT_FAILURE; //user must input a valid number } if (rate < 0){ cerr << "Sorry, you must input a positive number.\n"; return EXIT_FAILURE; //user must input a positive number } cout << "year principal\n" //column headings << "---- ---------\n"; double factor {1.00 + 0.01 * rate}; //converts the interest rate percent to a decimal number for (int year {1}; year <= nyears; ++year) { principal *= factor; //means principal = principal * factor cout << setw(4) << year << " $" << fixed << setprecision(2) << principal << "\n"; } return EXIT_SUCCESS; }