Thread: Looping Help

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    16

    Looping Help

    Im trying to build this simple program that computes the amount
    of time it takes to pay off a credit card debt.

    I have the user input:
    balance, interest_rate(monthly), & payment(monthly)

    The formula I came up with was:
    balance = balance - (payment - (balance * interest_rate));

    So lets say for example:
    Balance = $1500
    Monthly Payment = $42
    Monthly Interest Rate = .015

    With the above inputs, and the equation above you would get an answer of $1480.50. Because you would be paying off $19.50 the first month. How could i create a loop that would continue this formula with each new monthly balance, until it reached a balance of $0 and how could i have it print out how many months it took to pay off this debt?

    I also tried a variation of the formula below to find the number of monthly payments:
    N = –log(1–iA/P) / log(1+i)
    N = number of payments
    I = interest rate
    A = balance
    P = payment
    But it did not work very well, does C programming compute Logrithims (LOG, LN?)

    Any tips would be appreciated! Thanks...

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490

    Re: Looping Help

    Originally posted by zipfur


    does C programming compute Logrithims (LOG, LN?)

    Any tips would be appreciated! Thanks...
    yes, look into math.h.

  3. #3
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    This isn't the best code as it was thrown together fast, but it should do the job.
    Code:
    #include <stdio.h>
    
    int main ( void )
    {
    	float Bill;
    	float Monthly;
    	float Interest;
    	int MonthCount = 0;
    	int Time;
    	
    	printf("Enter the amount of your total bill:\n");
    	scanf("%f", &Bill);
    
    	printf("Enter the monthly payments you are making:\n");
    	scanf("%f", &Monthly);
    
    	printf("Enter the interest rate you are being charged:\n");
    	scanf("%f", &Interest);
    
    	while ( Bill >= 0 )
    	{
    		Bill = Bill-(Monthly * (Interest/100) + Monthly);
    		MonthCount++;
    	}
    	Time = MonthCount/12;
    	printf("\n\nIt will take you %d months to pay off this debt.\n", MonthCount);
    	printf("It will take you %d years to pay off this debt.", Time);
    	return 0;
    }
    The world is waiting. I must leave you now.

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    16
    Shadow thanks for the post, i appreciate your time!!! I was having trouble with that while loop - but this should set me straight -thanks...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. wierd looping effect after exporting 3ds to .x annimation
    By Anddos in forum Game Programming
    Replies: 3
    Last Post: 01-06-2009, 01:43 PM
  2. problems with prototype function looping
    By dezz101 in forum C Programming
    Replies: 5
    Last Post: 04-29-2008, 06:03 AM
  3. looping went berserk
    By miryellis in forum C Programming
    Replies: 7
    Last Post: 09-21-2004, 01:59 PM
  4. Looping questions
    By Peyote in forum C++ Programming
    Replies: 3
    Last Post: 09-15-2003, 11:01 PM
  5. looping and input
    By Kinasz in forum C Programming
    Replies: 2
    Last Post: 03-17-2003, 07:12 AM