Sep 3, 2010 at 10:29am UTC
Need some help with this problem:
You are given a 10000, how long would it take for you to become a millionaire?(Assume you could make 8% yearly interest on your money.)
Thanks in advance.
Sep 3, 2010 at 10:49am UTC
Nothing. I am new in C/C++. I don't understand yet the logic in using while.
Sep 3, 2010 at 1:25pm UTC
Hope this helps!
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
#include <stdafx.h> // Include Starting File
#include <iostream> // Include In/Out Stream
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char Test;
int Calc1 = 100;
int Calc2 = 8;
int Cash = 10000;
int Year = 0;
do
{
++Year;
Cash = Cash * Calc2 / Calc1 + Cash;
cout << "Cash after year " << Year <<"\n" ;
cout << "$ " << Cash <<"\n" ;
} while (Cash <= 1000000);
cout << "It takes " << Year <<" years to reach $" << Cash <<"\n" ;
cin >> Test;
return 0;
}
Last edited on Sep 3, 2010 at 1:35pm UTC
Sep 10, 2010 at 9:45am UTC
To Snaef and null thanks for the help. It really helped me a lot.
Sep 10, 2010 at 2:59pm UTC
Snaef: please don't solve homework problems for people.
Helping is great, but don't post full solutions. They're not going to learn anything if they just get their answers off the web.
Especially not if the code is uncommented and unexplained. He's just going to copy/paste that and submit to his teacher.
Sep 10, 2010 at 5:03pm UTC
Or if you desperately want to give the solution, write a really hard code, so the asker can't just hand it in (since it would be kinda suspicious if he'd come up with that)
:)
Cheers!