Hi again, I’m writing a program that will given that you have $10,000 in the bank with 4% interest and you take out $1000 every month, how many months will you be able to do that?
my program:
#include <stdio.h>
unsigned long int total=10000;
unsigned long int total_two;
unsigned long int total_three;
//unsigned int total_fn(void);
int main()
{
int months=0;
while(total>0)
{
total_two=(total-1000)*(104)/(100);
total_three=total_two;
total=total_three;
printf("%d ",total);
months++;
}
printf("If you have 250,000 dollars in your account with 4%% interest,
");
printf("And you withdraw 1,000 dollars a month, you will be able to withdraw for %d months.
",months);
return(0);
}
/unsigned int total_fn(void)
{
total=total104/100-1000;
return(total);
}*/
the problem is that when it runs, it prints wild random numbers and never gets to the printing the months because it is always greater than zero. the reason I have unsigned long int total_two&_three is because I thought that maybe the problem was total=total-1000 etc. but it still dosen’t work. What am I doing wrong? thanks