compound vs simple interest exercise..

Hello again, sorry to bombard the forum with noob questions but I was stuck on this problem yesterday, came back today and still can't figure it out.

Exercise : Daphne invests $100 at 10% simple interest, that is every year daphnes value increases by 10% of the principle(original investment).
Cleo invests $100 at 5% compound interest, the next year earns 5% of 105, so on and s on.

Write a program that calculates how long it will take in years for Cleo's investment to have a greater value than Daphne's, also output after how many years this occurs.

Here's my code.. nothing happens though, all it does is open up a screen that says Hello.(i put that in there because the screen was blank) should I be declaring the variables inside the "do" ? or should I be using a for loop?

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
#include <iostream>

using namespace std;

int main()
{
    cout << "Hello";
    double daphne = 100;
    double daphneincrement = (100 * .1);
    double cleo = 100;
    double cleoincrement = (cleo * .05);
    int years = 0;
    do
        {
        daphne += daphneincrement;
        cleo += cleoincrement;
        years += 1;
        }
    while (cleo <= daphne);

    
    cout << "It will take " << years << " years for Cleo's value to surpass Daphne' value." << endl;
    cout << "Cleo will have " << cleo << "dollars and Daphne will have " << daphne << " dollars. " << endl;
    
    cin.get();
    cin.get();
    return 0;
}


Notice that this here -> double cleoincrement = (cleo * .05); will only initialize cleoincrement.
It doesn't make it change every time cleo changes. You have to do it yourself:

1
2
3
4
5
6
7
8
9
10
11
12
//...
do
{
    daphne += daphneincrement;
    cleo += cleoincrement;

    //add this here!
    cleoincrement=(cleo * .05);

    years += 1;
} while (cleo <= daphne);
//... 
i'm pretty sure your my new favorite poster roshi :P
@george,

One of your classmates posted the same questions in s thread titled 'Exercise'. You should read the responses as they likely address your question as well.
Topic archived. No new replies allowed.