Thread: this code doesn't work please help me debug

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    38

    this code doesn't work please help me debug

    #include <stdio.h>
    #include <math.h>

    int main(void)

    {

    double r, a, p, x, powr, n;



    printf("How long is the loan in years?\n");

    scanf("%d", &n);

    n = n / 12;

    printf("How much did you borrow?\n");

    scanf("%lf", &a);

    printf("What is it's interest?\n");

    scanf("%lf", &r);

    x = r + 1;

    powr = pow((double) x , (double) n);

    p = (r * powr ) / ( powr - 1 );

    printf("your monthly payment is : %f", p);

    return 0;

    }



    see any errors?

  2. #2
    Registered User SKeane's Avatar
    Join Date
    Sep 2006
    Location
    England
    Posts
    234
    Code:
    #include <stdio.h>
    #include <math.h>
    
    int main(void)
    {
         double r, a, p, x, powr, n;
    
        printf("How long is the loan in years?\n");
        scanf("%d", &n);    /* n is a double not an integer !! So don't use %d */
    
        n = n / 12;
    
        printf("How much did you borrow?\n");
    
        scanf("%lf", &a);
    
        printf("What is its interest?\n");
    
        scanf("%lf", &r);
    
        x = r + 1;
    
        powr = pow((double) x , (double) n);
    
        p = (r * powr ) / ( powr - 1 );
    
        printf("your monthly payment is : %f", p);
    
        return 0;
    
    }

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    This is essentially the same problem raised here:

    http://cboard.cprogramming.com/showthread.php?t=83937

    From now on, newcstudent, please use code tags - and read the forum guidelines, too.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 11-15-2007, 01:36 AM
  2. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  3. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Game Programming
    Replies: 0
    Last Post: 10-14-2002, 01:27 PM
  4. << !! Posting Code? Read this First !! >>
    By kermi3 in forum C# Programming
    Replies: 0
    Last Post: 10-14-2002, 01:26 PM
  5. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 12:51 PM