powers and syntax question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cbrrr
    New Member
    • Sep 2008
    • 6

    powers and syntax question

    I am writing a mortgage calculator for class and am having some problems with the algebra expression and a syntax error at the end. I am posting just he equation so far and the error I get. I belie i am with in the rules please don't hammer if i'm not since this is my first class. there are some extra variables for later use.
    #include<iostre am>
    #include<cmath>
    using std::cout;
    using std::endl;

    int main()
    {
    //declare variables
    int principal, months, years;
    double rate, payment;

    //assign values to variables
    principal = 100000, xpayment = 84, years = 7, months = 12;
    rate = .0535;

    //calculations
    payment = [principal (1 + rate / 12), pow(0, 360), * (rate / 12)] / [( 1 + rate / 12) - 1];

    // output
    cout << endl;
    << "monthly payment is " << payment << " dollars";
    << endl;
    system("PAUSE") ;
    return 0;
    }
    the errors come up on the calculation line
    and <<"monthly payment is " <<payment<< " dollars" line.
  • boxfish
    Recognized Expert Contributor
    • Mar 2008
    • 469

    #2
    Your syntax error is easy to fix; either put more couts or omit the semicolons.
    The way it is now, it's three seperate statements,
    Code:
    cout << endl;
    and
    Code:
    << "monthly payment is " << payment << " dollars";
    and
    Code:
    << endl;
    and the last two are missing the cout, see.
    So like
    Code:
    cout << endl
         << "monthly payment is " << payment << " dollars"
         << endl;
    or
    Code:
    cout << endl;
    cout << "monthly payment is " << payment << " dollars";
    cout << endl;
    should fix it.

    As for the algebra, you can't use [ and ] instead of ( and ). In C++, square brackets mean something completely different. Just replace the square ones with round ones; it's okay to nest round ones inside of round ones. Also, b(a + c) will not multiply b by a + c; you have to use the * operator: b * (a + c)
    I don't know what the commas inside your expression mean, but they shouldn't be there. pow(0, 360) will raise zero to the 360th power, which of course is just zero. I'm guessing that's not what you want. To use pow(), you have to have the value you're raising to a power and the power you're raising it to both inside the parentheses. So for example, pow(4, 3) is 64. Except that I think the numbers have to be floats or doubles, so make that: pow(4.0, 3.0) is 64.0. Here's a reference page on pow.

    I hope this helps a bit.

    Also, as it says in the posting guidelines, it helps if you use code tags around your code.

    Good luck.

    Comment

    • cbrrr
      New Member
      • Sep 2008
      • 6

      #3
      Thanks for the help I really appreciate it.

      Comment

      Working...