output from bank type problem

This is a discussion on output from bank type problem within the C Programming forums, part of the General Programming Boards category; Hi everyone, I'm hoping someone might be able to help me with this problem. What i'm trying to do is ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    3

    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!!

  2. #2
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    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

  3. #3
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356

    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...
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  2. Replies: 12
    Last Post: 10-16-2008, 01:07 PM
  3. Base converter libary
    By cdonlan in forum C++ Programming
    Replies: 22
    Last Post: 05-15-2005, 02:11 AM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 09:57 AM
  5. Erros in Utility Header File
    By silk.odyssey in forum C++ Programming
    Replies: 4
    Last Post: 12-22-2003, 06:17 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21