#include #include #include using namespace std; int main() { double principal {0.00}; double yield {0.00}; int duration{0}; cout <<"What is your beginning balance?\n"; cin >> principal; if (!cin) { cerr << "Please enter a non-negative account balance.\n"; return EXIT_FAILURE; } cout << "Thank you. Please enter your target annual yield as a percentage.\n"; cin >> yield; if(!cin) { cerr << "Not a valid yield rate.\n"; return EXIT_FAILURE; } cout <<"Thank you. What is the term of your investment in years?\n"; cin >> duration; if(!cin) { cerr <<"This is not a vaild investment duration. Try again.\n"; return EXIT_FAILURE; } if( duration < 0) { cerr <<"Unfortunately, we haven't yet mastered time travel. Please enter a positive number.\n"; return EXIT_FAILURE; } const double factor {yield*.01 + 1}; double balance {principal}; cout << fixed << setprecision (2) << "\n\nStarting with $" << balance << " and an expected return of " << yield << "% over a " << duration << " year term, annualized returns are as follows:\n"; for ( int term {duration} ; term >= 2 ; --term ) { double growth {balance *= factor}; cout << fixed << "With "<< (term - 1) << " years remaining until maturation, your expected valuation is $"; cout << fixed << setprecision (2) << growth << ".\n"; if (term % 10 == 0) { cout <<"\n"; } if((term - 1) == 1) { cout << "Upon maturation, your expected valuation is $"; cout << fixed << setprecision (2) << growth << ".\n"; } } return EXIT_SUCCESS; }