#include #include //for the "i/o manipulators" setw and setprecision #include using namespace std; //Interest is 6% annually. int main() { cout<< "What is the principal? "; double principal {00.00}; //start with this many dollars cin >> principal; if (!cin) { cerr << "Sorry, that was not a number.\n"; return EXIT_FAILURE; } if (principal <= 0) { cerr << " Sorry, the principal must be a positive.\n"; return EXIT_FAILURE; } cout << "For how many years? "; int nyears {0}; cin >> nyears; if (!cin) { cerr << "Sorry, that was not a number.\n"; return EXIT_FAILURE; } if (nyears <= 0 ) { cerr << "Sorry, the numer of years must be a positive.\n"; return EXIT_FAILURE; } cout << "What is the annual rate?"; double rate {0.00}; cin >> rate; if (!cin) { cerr << "Sorry, that was not 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(4) << year << " $" << fixed << setprecision(2) << principal << "\n"; } return EXIT_SUCCESS; }