using namespace std; #include int Years_To_Millionaire (double base, double rate); int Years_To_Millionaire (double base, double rate) // Returns number of years to become a millionaire if you start // with base dollars and invest it at annual interest rate { double total; int years; years = 0; total = base; while (total < 1000000.0) { total *= (1.0 + rate); years++; } return years; } int main () { double initial_investment, annual_rate; // Get information from user cout << "Initial investment: "; cin >> initial_investment; cout << "Annual interest rate: "; cin >> annual_rate; // Compute number of years to make a million if (initial_investment <= 0.0) cout << "\nSorry, you'll never become a millionaire\n" << "by investing a non-positive amount.\n"; else if (initial_investment >= 1000000.0) cout << "\nYou're already a millionaire.\n"; else if (annual_rate <= 0.0) cout << "\nSorry, you'll never become a millionaire\n" << "by investing at a non-positive rate.\n"; else cout << "\nYou'll be a millionaire in " << Years_To_Millionaire (initial_investment, annual_rate / 100.0) << " years.\n"; }