# output from bank type problem

• 09-03-2002
IzaakF
output from bank type problem
Hi everyone, I'm hoping someone might be able to help me with this problem. What i'm trying to do is get an opening balance,an annual rate of interest and a yearly withdrawal figure from the user. Then output like this:

year...balance...interest....withdrawn............ ...new balance
1 ......100..........0.5 ..............10 ............................95
2........95............0.5..............10........ ...................89.75
3........89.75.......0.5..............10.......... .................84.23

and so on... until the new balance reaches 0
and then output the amount of years it took to empty the account.

I think the problem is probably my poor understanding of loops. Any help you might have would be great!! Thankyou.

This is what i have so far.

#include <stdio.h>
int main(void)
{

float bal,rate,take;
float count,new;

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("\n\n\nyear amount interest withdrawn new balance\n\n");

bal=bal*(1+rate)-take;
new = bal;

for (count=1;count<=10;count++)

printf("%5f %10.2f %10.2f %10.2f
%10.2f\n",count,bal,rate,take,new);

}
p.s I,m new to this so i apologise if this is a mess!!
• 09-03-2002
Draco
First of all, you missed the opening brace on your for loop. It might be cleaner to instead of using %5f,%10.2f, etc. to use tabs i.e. printf(%f\t\t\%f\t\t%f) etc. and then go to a new line at the end of the printing line. Also, start using code tabs when you post. All you have to do is type in[code] and[\code] at the beginning and end of your code segments. It's easier to distinguish the code, plus the board vets get mad if you don't:D
• 09-04-2002
datainjector
help
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...