#include #include //for the "i/o manipulators" setw and setprecision #include using namespace std; //Interest is 6% annually. int main() { cout << "What is the interest rate?"; double principle {0.00}; //start with this many dollars cin >> principle; if (!cin) { cerr << "Sorry, that wasn't a number.\n"; return EXIT_FAILURE; } if (principle <=0) { cerr << "Sorry, the principle 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"; retun EXIT_FAILURE; } if (nyears <= 0) { cerr << "Sorry, the number of years must be positive.\n"; return EXIT_FAILURE; } cout << "What is the annual rate? "; 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 principle\n" //column headings << "____ _________\n"; for (int year {1}; year <= nyears; ++year) { principle *= factor; //meand principle = principle * factor cout << setw(4) << year << " $" << fixed << setprecision(2) << principal << "\n"; } return EXIT_SUCCESS;