Thread: Example

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    4

    Example

    Does anybody have an example of code for a mortgage calculator which prints out a table showing balance outstanding each week with total interest paid until the capital is fully repaid,when amount borrowed, interest rate and monthly payment are entered?
    Thanks in advance.

  2. #2
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    post your ideas for one

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    4
    my ideas are above.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    What's to think about?

    debt = debt + interest;
    debt = debt - repayment;
    total = total + repayment;

    Rinse and repeat until debt is <= 0
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534


    Of course be sure to do some error checking to make sure you don't make an infinite loop if for example the monthly repayments are not large enough, and the debt grows larger and larger....

    ~/

  6. #6
    Registered User
    Join Date
    Nov 2003
    Posts
    4
    I have made a start on the code, will this work, are there any errors, i am a complete newbie to programming as you can probably tell! Any input would be much appreciated.
    Thanks.

    Code:
    # include <stdio.h>
    # include <math.h>
    # include <string.h>
    # include <stdlib.h>
    
    void main ()
    
    {
    	float capital,rate,payment,week,int,debt,tint,year,newweek;
    
    	printf(“Please enter amount borrowed (£)\n\r”);
    	scanf(“%f,&capital);
    	printf(“Please enter interest rate(%)\n\r”);
    	scanf(“%f,&rate);
    	printf(“Please enter monthly payment (£)\n\r”);
    	scanf(“%f,&payment);
    
    printf(“Year\t Week\t Balance Outstanding\t Total Interest\n\r”);
    
    		week=1
    		int=(rate/364*7/100)*capital
    		debt=capital+(int*capital*week)
    		tint=int*week
    		year=week/12+1%.0
    
    printf(“%f,\t, %f,\t, %f,\t, %f,\t”,year,week,debt,tint);
    
    		newweek=week++
    		int=(rate/364*7/100)*capital
    		debt=capital+(int*capital*week)
    		tint=int*week
    		year=week/12+1%.0
    
    printf(“%f,\t, %f,\t, %f,\t, %f,\t”,year,week,debt,tint);
    
    while (debt>0)
    	{
    newweek=newweek++
    		int=(rate/364*7/100)*capital
    		debt=capital+(int*capital*week)
    		tint=int*week
    		year=week/12+1%.0
    
    printf(“%f,\t, %f,\t, %f,\t, %f,\t”,year,week,debt,tint);
    }

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    51
    well first u can't use keywords for variable identifiers, so u wouldn't beable to use int as a float variable.

    int is the keyword for declaring an integer variable.

    it seems that u've missed the closing quotations for all your scanf function calls

    [code]
    scanf(“%f,&capital);

    // should be like
    scanf("%f", &capital);
    [code]

    atm thats call i can see.

    So just add the closing quotation marks and change the name of the 'int' variable to something else.

  8. #8
    Registered User
    Join Date
    Oct 2003
    Posts
    10
    main returns int, always, think about it, it makes perfect sense.

Popular pages Recent additions subscribe to a feed