Interest rate

Ask the user to enter how much money will be deposited
If $1000 are to be deposited, the account will have the same balance
If more than $1000, find how many months it will take to double the money
First calculate the interest, add it to the $1000 then deduct $5. Then calculate the interest again but on the original value after adding interest and deducting charges. Repeat until money doubles
If less than $1000, find how many months it will take for the account to be reduced to zero
First calculate the interest, add it to the $1000 then deduct $5. Then calculate the interest again but on the original value after adding interest and deducting charges. Repeat until money becomes 0.
The interest rate is 0.5%
I wrote this program but it's not working and I can not identify the reason
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
28
  #include <iostream>
using namespace std;

int main()
{
double n;
double sum=0;
int i=0;
cout<<"Please enter the amount of money you want to deposit into the account"<<endl;
cin>>n;
if (n==1000){
	cout<<"The account will have the same balance at the end of each month"<<endl;
} else if (n<1000){
	while (n<=0){
		i=i+1;
		n=((n*1.005)-5);
	}
	cout<<i<<endl;
} else {
	while (n>=n*2){
		i=i+1;
		n=((n*1.005)-5);
	}
	cout<<i<<endl;
}

	return 0;
}
sme97 wrote:
I wrote this program but it's not working and I can not identify the reason
What do you mean by "not working"? Does it cause your computer to bluescreen? Does it shut off your neighbor's water? Does it send angry emails to the president? You need to be specific.
It always gives me 0 as the number of months it takes to double the money if I entered a number more than 1000 or it also gives me 0 as the time it takes for the money to become 0 when I enter a number less than 1000.
Last edited on
You should check your while loop conditions. Remember, the condition needs to be true for the loop to continue.
Thank you very much, it is fine now, I flipped the signs in the while loop condition by mistake
Last edited on
Topic archived. No new replies allowed.