incorrect answer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thatwhiteguy
    New Member
    • Nov 2007
    • 10

    incorrect answer

    I have been working on this program for a few days now, and I am at a loss as to what is wrong. I am new to c++, so I am sure that it must be something simple that I am missing, but I can not pin point it. Below is my code, and no matter what I input it gives me the same answer: $1.#INF. All I need for it to do is calculate the monthly payments .


    [CODE=cpp]#include <iostream>

    using namespace std ;
    //function prototype
    double payment(double balance, double AIR, int num_of_pay);
    //funciton prototype
    double power (int num_of_pay, double AIR);
    int main ()
    {
    double month_pay; //
    double balance; //amount of loan
    double AIR; //annual interest rate
    int num_of_pay ; //number of payments over course of loan
    double result;

    cout<< "Welcome to the loan payment calculator program!"<<endl ;

    cout<< " Please enter the loan amount:"<<endl ;
    cin>> balance;

    cout<< " Please enter the annual interest rate as a percentage, not a decimal:"<<endl ;
    cin>> AIR;

    cout<< "Please enter number of payments you will pay:"<<endl;
    cin>> num_of_pay;
    month_pay = payment(balance , AIR, num_of_pay);
    cout<< "The amount of your monthly payment is: $" << month_pay <<endl;

    system("PAUSE") ;
    return (0);
    }

    double payment(double balance, double AIR, int num_of_pay)
    {

    double month_pay;

    AIR = (AIR/100.00)/12.00;

    month_pay = (balance * AIR) / ( 1.0 - power ((! + AIR), -num_of_pay));

    return (month_pay);
    }


    double power (int num_of_pay, double AIR)
    {
    double result;
    int i;

    result = 1.0;
    for (i=0; i< abs (num_of_pay); i++) result *= (1 + AIR );

    if (num_of_pay > 0)
    return (result);
    else
    return (1.0 / result);
    }[/CODE]
    Last edited by Ganon11; Dec 15 '07, 01:03 AM. Reason: Please use the [CODE] tags provided.
  • mschenkelberg
    New Member
    • Jun 2007
    • 44

    #2
    what do you pass to the program?

    Comment

    • thatwhiteguy
      New Member
      • Nov 2007
      • 10

      #3
      Originally posted by mschenkelberg
      what do you pass to the program?

      I pass the amount of the loan. We'll say 5700. The amount of interest, we'll say 12 . And the amount of total payments, we'll say 36.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Originally posted by thatwhiteguy
        month_pay = (balance * AIR) / ( 1.0 - power ((! + AIR), -num_of_pay));
        So, what's the ! for ??? ............... ............... .......^

        Comment

        Working...