Daily compound interest

This is a discussion on Daily compound interest within the C Programming forums, part of the General Programming Boards category; I've been doing well in this darn class up until this assignment. oh well, this is my first class and ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Location
    San Diego
    Posts
    10

    Daily compound interest

    I've been doing well in this darn class up until this assignment. oh well, this is my first class and i'm only 5 weeks in. anyway, here is the program specifics:

    Suppose you invest $100.00 at an interest rate of 10% per year. The interest is computed at the end of each day, and is added to your account (i.e., the interest is compounded daily). Print what the account value will be at the end of each year for 20 years. Use data type double for money. Assume 365 days per year, hence the daily interest rate is 10 / 365. Do not use the pow function.

    This is what I have so far:
    Code:
    double principal = 100.00;
       int day, year;
       double rate = .01* (10/365); 
      
       printf("Year\tAmount on deposit ($)\n");
    
       for(year = 1; year < 20; year++);
       {  
         
           for(day = 1; day <= 365; day++);
           {
           principal += (principal * rate); 
           } 
       printf(" %d\t\t%.2f \n", year, principal); 
       }
    I thought I had a decent understanding of the for loop, but now I feel like I'm missing it. How I tried to write this was having a for loop inside a yearly for loop that performed the daily compound for a year and then after that cycle it would print. Do for loops require more than just a simple printf statement? I feel like I am close, but who really knows. The restriction of not using the pow function makes it tricky. I haven't developed the intuition yet I suppose. Any help is appreciated.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,166
    You have semi-colons at the end of your for() loops which means that the code you think is part of the for() loop body, is actually outside of it and only getting executed once after the for() loops completes its meaningless cycle that just increments the day/year counters.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 02-11-2009, 11:54 AM
  2. need help with compound interest
    By JoelearningC in forum C Programming
    Replies: 4
    Last Post: 03-09-2008, 10:32 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