Question about while

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.
What do you have so far?
Nothing. I am new in C/C++. I don't understand yet the logic in using while.
If you don't understand how while loop works at all, you should read the tutorial:
http://www.cplusplus.com/doc/tutorial/
and
http://www.cplusplus.com/doc/tutorial/control/#while
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
To Snaef and null thanks for the help. It really helped me a lot.
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.
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!
Topic archived. No new replies allowed.