need help with compound interest

This is a discussion on need help with compound interest within the C Programming forums, part of the General Programming Boards category; Folks, I've got this code below that creates an interest table with the interest compounded annually. I want to convert ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    15

    need help with compound interest

    Folks,
    I've got this code below that creates an interest table with the interest compounded annually. I want to convert it to compound the interest on a monthly basis instead. Can anyone help and give advice as to what I need to focus on changing? Thanks!

    Code:
    /*Prints a table of compound interest */
    
    #include <stdio.h>
    
    #define NUM_RATES (sizeof(value) / sizeof(value[0]))
    #define INITIAL_BALANCE 100.00
    
    main()
    {
    	int i, low_rate, num_years, year;
    	float value [5];
    
    	printf("Enter interest rate: ");
    	scanf("%d", &low_rate);
    	printf("Enter number of years: ");
    	scanf("%d", &num_years);
    
    	printf("\nYears");
    	for (i=0; i<NUM_RATES; i++)   {
    		printf("%6d%%", low_rate+i);
    		value[i] = INITIAL_BALANCE;
    }
    printf("\n");
    
    for (year = 1; year <= num_years; year++)   {
    	printf("%3d      ", year);
    	for (i=0; i<NUM_RATES; i++)  {
    		value[i] += (low_rate+i) / 100.00 * value[i];
    		printf("%7.2f", value[i]);
    	}
    	printf("\n");
    }
    return 0;
    }

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    How do you think the interest would be calculated on a monthly basis?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    If your bank tells you they give you 12% interest compounded monthly, what that means is that you get 1% per month.

    As an aside: I realize that what you have probably (I hope) makes sense to you, but it is the most inefficient method of computing an interest table I have ever seen (not that I collect them or anything, or that this problem is hard enough so that it matters). There is a formula for this sort of thing; consider using that, or if you don't like formulas, at least storing the last row in an auxiliary array so that you don't have to compute it all over again for the next row.

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    1&#37; per month results in 12.68% per year
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by vart View Post
    1% per month results in 12.68% per year
    Yes. That's why it's called "the magic of compound interest".

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-01-2009, 12:06 AM
  2. Replies: 4
    Last Post: 02-11-2009, 11:54 AM
  3. Compound Interest Formula
    By veronicak5678 in forum C++ Programming
    Replies: 3
    Last Post: 09-16-2007, 05:16 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. compound interest
    By bliznags in forum C Programming
    Replies: 11
    Last Post: 03-20-2005, 12:46 AM

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