I have an exercise again and I got blocked again. The exercise is:
Daphne invests $100 at 10% simple interest. That is, every year, the investment earns
10% of the original investment, or $10 each and every year:
interest = 0.10 × original balance
At the same time, Cleo invests $100 at 5% compound interest. That is, interest is 5% of
the current balance, including previous additions of interest:
interest = 0.05 × current balance
Cleo earns 5% of $100 the first year, giving her $105. The next year she earns 5% of
$105, or $5.25, and so on. Write a program that finds how many years it takes for the
value of Cleo’s investment to exceed the value of Daphne’s investment and then displays
the value of both investments at that time.
And I wrote this code that is not working:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
double deposit1, deposit2, interest1 = 10, interest2= 5, simple, compound, years =1;
cout<< " Enter your deposit for first choice "<< endl;
cin>> deposit1;
cout<< " Enter your deposit for the second choice "<< endl;
cin>>deposit2;
while(simple > compound)
{
simple = deposit1 + deposit1 * interest1/100 * years;
compound = deposit2 * pow(1.00 + interest2/100, years);
years++;
}
cout<<years<<endl;
system ("pause");
return 0;
}
| |