help with this problem

3. 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.

so I did
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

const float s = 10/100;
const float c = 5/100;

int main()
{
    using namespace std;
    int Cleo = 100;
    int daphne = 100;
    do{
        Cleo * c;
        daphne * s;
        
        }while(Cleo!=daphne);
        cout << Cleo;
        cout << daphne;
        cout << endl;
    
    system("pause");
    return 0;
}

how should be the answer
Last edited on
change cleo and daphne's type to float/double,
lines 12 and 13 is meaningless in C++ -store the result somewhere, hint: x = x + 1; and look at your while condition again -the loop should stop after the first iteration because the result (if you coded it correctly) would be (Cleo * c) < (daphne * s)

extra: give a more meaningful variable name, and I prefer 0.1 to 1/10

edit: there could be problems later too with comparing floating point numbers try google for C++ rounding errors and such :\

edit2: my bad... ignore the strikethrough-ed sentence :p
Last edited on
Topic archived. No new replies allowed.