This might help u ...
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
float bal,rate,take, new_bal;/* dont use new as a variable name.Because its a keyword*/
int count=0;
printf( "Enter an opening balance: " );
scanf( "%f",&bal );
printf( "Enter an interest rate: " );
scanf( "%f" ,&rate );
printf( "Enter an amount to be withdrawn each year: ");
scanf( "%f",&take );
printf("%4s%10s%12s%13s%15s", "Year","Amount","Interest","Withdrawn","New Balance");
printf( "\n" );
while ( new_bal > 0 )
{
count++;
new_bal=bal*(1+rate)-take; /* Your formula is wrong*/
printf( "%4d%10.2f%12.2f%13.2f%15.2f\n",count,bal,rate,take,new_bal);
bal = new_bal;
}
printf (" The years it took to empty the account %d", count );
system("pause");
return 0;
}
First of all what are u trying to calculate or whats the formula??? ..Well i have fixed every thing execpt the formula ...i mean ur calculation its wrong .... check it and make it correct sfter that every thing will work fine....
okay if u execute it ...its gonna go in an infinite loops thats because ur calculation is wrong.. if u wanna c how the program work ...In the while statment remove (new_bal > 0 ) and put ( count != 10 )..The problem is that the formula u used just keeps on incresing but not decreasing so it will never come to zero...