#include #include //for the "i/o manipulators" setw and setprecision #include #include using namespace std; //Interest is 6% annually. int main() { int nyears {0}; double principal {0.00}; //start with this many dollars //Get principal from user cout << "Please enter your initial principal amount: $"; cout << "what is the principal"; cin >> principal; if (!cin || principal <=0.00) { cerr << " Error: invalid principal amount. Please enter a positive number.\n"; // Clear error flag and ignore remaining input to prevent infinite loops // cin.clear(); cin.ignore( numeric_limits::max(), '\n'); return EXIT_FAILURE; } cout << "what is the annualinterest rate?\n"; cin >> rate; if (!cin || rate <=0) { cerr << "Error: Invalid interest rate. Please enter a positive number.\n"; cin.clear(); return EXIT_FAILURE } //make sure the rate is reasonable, positive number. //each year multiply the principal by the following factor //for example, if the rate is 6, then factor will be 1.06 double factor {1.00 + .01 * rate}; for (int year {1}; year <= 10; ++year) { principal *= 1.06; //means principal = principal * 1.06 cout << " " << setw(2) << year << " $" << fixed << setprecision(2) << principal << "\n"; } return EXIT_SUCCESS; }