I gave some thought to what was mention and this is what i came up with ->
Code:
#include <iostream>
#include <iomanip>
using namespace std;
const double INT = 0.10;
int main()
{
int years=0, x=0;
double P0=0, Px=0, P1=0, interest=0;
cout << fixed << showpoint;
cout << setprecision(2);
cout << "Program that reads an initial amount and computes "
<< "the total in the account on your sixtieth birthday." << endl << endl;
cout << "Enter the initial amount of the account -> ";
cin >> P0;
Px = P0;
cout << "Enter the amount of years the account remain untouch -> ";
cin >> years;
cout << endl << endl;
cout << "The initial investment was $" << P0 << " . The total amount accumulated after "
<< years <<" years, if $" << P0 << " is allowed to compound with an interest of 10.00%,"
<< "comes to $";
for (x = 0; x != years; x++)
{
P1 = P0 + ( P0 * INT);
while (P0 < P1)
P0 = P1;
}
cout << P1 <<'.' << endl << endl;
cout << "The total amount accumulated after " << years << " (years + 1) years,"
<<" if $" << Px << " is allowed to compound with an interest of 10%, comes to $";
years += 1;
for (x = 0; x != years; x++)
{
if (x == years - 1)
interest += (Px * INT);
P1 = Px + ( Px * INT);
while (Px < P1)
Px = P1;
}
cout << P1 << " ." << endl << endl;
cout << "The interest earned during this year is $" << interest
<< ".If interest is withdrawn each year thereafter, my income is $"
<< (P0 / 12) << " per month." << endl << endl;
return 0;
}
I was wondering it anyone can make any comment or mention anyways of improving the program to make it more efficient.
THANKZ