Suppose your $1,000 is earning interest at 4% per year.
How many years you need to double your money?

Write a program to calculate the number of years!

Whew, it took me a while, but I think I've got it. Your turn.

(at least post what you have so far so someone can help you with your code)

Hmm... Obscure question. :P Is the interest computed at the end of each year or each month or each week or each day? :D Does the answer have to be in a whole year or decimal or year & month & day? ;)

#include <iostream>
using namespace std;

int main(){
double money=1000;
int years=0;

while(money<2000) {

money=money+4*money/100;
years++;
}
cout<<"after "<<years<<endl;

return 0;
commented: Do not give answers away like that, it was likely this OP's homework -1
commented: gave code +0

It's already been solved, but for the above equation:

money *= (400/32)^9

would be much more suitable. C++ only excepts quadnobial equations with bitwise operation *=.

money *= (400/32)^9

??? I don't see any equation like that above? Also, the value of 'money' would go sky rocket in one go ???

??? I don't see any equation like that above? Also, the value of 'money' would go sky rocket in one go ???

Just ignore that post completely. It's ridiculous on so many levels. Then again, the OP deserves no better. With any luck, the OP will submit that line of code to the professor and will have to justify it in front of the class.

1. ^ is the bitwise operator
2. I learned how to compound interest in 5th grade.
3. quadnobial is a non-existent equation
4. It was sarcastic
5. The OP obviously fell asleep in class or didn't listen, and as a result he should get a bad grade, though there's a 75% chance he'll copy that code and have no idea how it works.

Suppose your $1,000 is earning interest at 4% per year.
How many years you need to double your money?

Write a program to calculate the number of years!

You didn't indicate how you are going to pay for the answer ;)
Anyway I hope your professor is reading here so that you get big fat zero :)

>> 4. It was sarcastic

Glad to hear it. I was hoping so.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.