Thread: I have know idea what is going on with my code and/or my equation(again)

  1. #1
    Registered User
    Join Date
    Oct 2013
    Posts
    33

    I have know idea what is going on with my code and/or my equation(again)

    Ok so i have know idea why every time i try to print the results of this
    equation came up with to calculate a loans total cost.

    This code right here
    Code:
    float getloanamount(float payment,float months,float yearlyrate)
    {
        float loanamount;
        float i = (yearlyrate/1200);
        loanamount = payment*months*100/(i/100)/100;// Equation
        printf("test");
        return loanamount;
    }
    Always comes up with 0.000000 no matter what i type in. If anyone knows what the heck is going on here and how i can fix it please do say so.

    B.T.W I am using this code to take in the necessary parameters and then print them out.

    Code:
     {
                 int numberofpayments;
                 float yearlyrate ;
                 float sizeofpayment = 0.0;
                 float loansize ;
                 printf("Please enter in the number of yearly payments:");
                 scanf("%i",&numberofpayments);
                 putchar('\n');
                 printf("Number of payments:%i\n",numberofpayments);
                 printf("Please enter in the yearly rate(interest) of the loan:");
                 scanf("%f",&yearlyrate);
                 putchar('\n');
                 printf("Yearly rate:%f\n",yearlyrate);
                 printf("Please enter in the loan size:");
                 scanf("%f",&loansize);
                 roundtopennies(&loansize);
                 putchar('\n');
                 printf("Loan size:%f\n",loansize);
                 sizeofpayment = getloanamount(sizeofpayment,numberofpayments,yearlyrate);
                 printf("The loan's size is:%f\n",sizeofpayment);
             }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You set payment to 0. You then multiply it by a bunch of things. It will still be zero when you are done. Your formula should start with the amount borrowed.

  3. #3
    Registered User
    Join Date
    Oct 2013
    Posts
    33
    Dur,Dur,Dur what the heck is wrong with me. I meant to put the loansize there not sizeofpayment . Once again i find my code not working because of something so dum. Anyways thank you. I am really starting to like this Forum business

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. IDEA: code a defragger
    By Waldo2k2 in forum Contests Board
    Replies: 6
    Last Post: 03-18-2003, 08:44 PM
  2. IDEA: Equation solver
    By Magos in forum Contests Board
    Replies: 2
    Last Post: 01-07-2003, 11:46 AM
  3. IDEA: Equation Parser
    By ygfperson in forum Contests Board
    Replies: 0
    Last Post: 08-12-2002, 11:31 PM