Help! Investment program

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.


I wrote the program, but it says it took 27 years for Cleo to exceed Dapne's investment.

Daphne invested 100$ with 10% simple interest.
Cleo invested 100$ with 5% compund interest.

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
27
28
29
30
struct bank{
double balance;
double interest;
};

main(){
bank Daphne =
{
    100,
    0.10
};
bank Cleo =
{
    100,
    0.05
};
int years = 0;
    while(Daphne.balance >= Cleo.balance){
        Daphne.interest *= 100;
        Daphne.balance += Daphne.interest;
        Daphne.interest = 0.10;
        Cleo.interest *= Cleo.balance;
        Cleo.balance += Cleo.interest;
        Cleo.interest = 0.05;
        years++;
    }
cout << "It took " << years << " years for Cleo to exceed the value of Daphne's investment.\n";
cout << "Cleo's current balance is $" << Cleo.balance << ".\n";
cout << "Daphne's current balance is $" << Daphne.balance << ".\n";
}


Is this the correct formula? (I'm bad at maths sorry lol).
Last edited on
Topic archived. No new replies allowed.