I tried it but i got the coding all wrong maybe.
Write a program that uses a while loop to determine how long it takes for an investment to double at a given interest rate. The input will be an annualized interest rate, and the output is the number of years it takes an investment to double.
Note: the amount of the initial investment does not matter; you can use USD 100.
Here's my code..Please help me. I cant make out a proper while loop.
int main()
{
float rate;
int count=1;
float Amount=0;
float Interest=0;
float investment=100;
cout<<"Enter the % annual rate: ";
cin>>rate;
while(investmen t<=(2*investmen t)){
Interest=((inve stment*rate*cou nt)/100);
Amount=Interest +investment;
if(investment== (2*investment)) {
cout<<"The number of years it takes for an investment to double is: "<<count<<" years"<<endl;
}
count++;
}
return 0;
}
Write a program that uses a while loop to determine how long it takes for an investment to double at a given interest rate. The input will be an annualized interest rate, and the output is the number of years it takes an investment to double.
Note: the amount of the initial investment does not matter; you can use USD 100.
Here's my code..Please help me. I cant make out a proper while loop.
int main()
{
float rate;
int count=1;
float Amount=0;
float Interest=0;
float investment=100;
cout<<"Enter the % annual rate: ";
cin>>rate;
while(investmen t<=(2*investmen t)){
Interest=((inve stment*rate*cou nt)/100);
Amount=Interest +investment;
if(investment== (2*investment)) {
cout<<"The number of years it takes for an investment to double is: "<<count<<" years"<<endl;
}
count++;
}
return 0;
}
Comment