Simple Algorithm

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Karl Heinz Buchegger

    #16
    Re: Simple Algorithm

    savesdeday wrote:[color=blue]
    >
    >
    > Last quick question, I am having trouble incorporating the equation to
    > find the interest earned into C++. The equation is:
    > Total interest earned = [(1+I/12)12 - 1]*B, and we are supposed to
    > use cmath to do this. If I try to type in :
    > tot_interest= (pow(1+rate/12, 12)-1)*balance
    > and try to compile it, I get an error.[/color]

    What error?

    The compiler emits error messages to give you a hint on what is wrong
    in your code. Read those error messages!
    [color=blue]
    > What is the correct format to
    > implement the equation [(1+I/12)12 - 1]*B (using <cmath>) ?[/color]

    What you have seems fine.
    So what does the error message say?

    --
    Karl Heinz Buchegger
    kbuchegg@gascad .at

    Comment

    • osmium

      #17
      Re: Simple Algorithm

      Karl Heinz Buchegger wrote:
      [color=blue]
      > savesdeday wrote:[color=green]
      > >
      > >
      > > Last quick question, I am having trouble incorporating the equation to
      > > find the interest earned into C++. The equation is:
      > > Total interest earned = [(1+I/12)12 - 1]*B, and we are supposed to
      > > use cmath to do this. If I try to type in :
      > > tot_interest= (pow(1+rate/12, 12)-1)*balance
      > > and try to compile it, I get an error.[/color]
      >
      > What error?
      >
      > The compiler emits error messages to give you a hint on what is wrong
      > in your code. Read those error messages!
      >[color=green]
      > > What is the correct format to
      > > implement the equation [(1+I/12)12 - 1]*B (using <cmath>) ?[/color]
      >
      > What you have seems fine.[/color]

      I think he needs some decimal points in his code, for starters.


      Comment

      • Karl Heinz Buchegger

        #18
        Re: Simple Algorithm

        osmium wrote:[color=blue]
        >
        > Karl Heinz Buchegger wrote:
        >[color=green]
        > > savesdeday wrote:[color=darkred]
        > > >
        > > >
        > > > Last quick question, I am having trouble incorporating the equation to
        > > > find the interest earned into C++. The equation is:
        > > > Total interest earned = [(1+I/12)12 - 1]*B, and we are supposed to
        > > > use cmath to do this. If I try to type in :
        > > > tot_interest= (pow(1+rate/12, 12)-1)*balance
        > > > and try to compile it, I get an error.[/color]
        > >
        > > What error?
        > >
        > > The compiler emits error messages to give you a hint on what is wrong
        > > in your code. Read those error messages!
        > >[color=darkred]
        > > > What is the correct format to
        > > > implement the equation [(1+I/12)12 - 1]*B (using <cmath>) ?[/color]
        > >
        > > What you have seems fine.[/color]
        >
        > I think he needs some decimal points in his code, for starters.[/color]

        The following compiles fine for me. It uses the exact
        line the OP provides. It even comes up with a result which
        seems to be plausible although I have not checked the exact
        numbers.

        #include <iostream>
        #include <cmath>

        using namespace std;

        int main()
        {
        double tot_interest;
        double rate = 0.2;
        double balance = 1.0;

        tot_interest= (pow(1+rate/12, 12)-1)*balance;

        return 0;
        }

        --
        Karl Heinz Buchegger
        kbuchegg@gascad .at

        Comment

        Working...