Simple Algorithm

Discussion in 'C++' started by savesdeday, Mar 1, 2004.

  1. savesdeday

    savesdeday Guest

    In my beginnning computer science class we were asked to translate a
    simple interest problem. We are expected to write an algorithm that
    gets values for the starting account balance B, annual interest rate
    I, and annual service charge S. Your algorithm would then compute and
    print out the total amount of interest earned during the year and the
    final account balance at the end of the year (assuming that interest
    is compounded monthly, and the service charge is deducted once, at the
    end of the year). In this lab assignment you will convert this
    algorithm into a C++ program.
    A sample run of your program would look like the following:
    Enter the beginning account balance: 300.00
    Enter the annual interest rate: 5.5
    Enter the annual service charge: 10
    The total interest earned is: 16.9224
    The final account balance is: 306.922

    Here are some formulas for the quantities to be printed:
    Total interest earned = [(1+I/12)12 - 1]*B
    Final account balance = B + (total interest earned) - S

    Can anyone help me out with this? Thank you kindly in advance.
     
    savesdeday, Mar 1, 2004
    #1
    1. Advertising

  2. "savesdeday" <> wrote...
    > In my beginnning computer science class we were asked to translate a
    > simple interest problem. We are expected to write an algorithm that
    > gets values for the starting account balance B, annual interest rate
    > I, and annual service charge S. Your algorithm would then compute and
    > print out the total amount of interest earned during the year and the
    > final account balance at the end of the year (assuming that interest
    > is compounded monthly, and the service charge is deducted once, at the
    > end of the year). In this lab assignment you will convert this
    > algorithm into a C++ program.
    > A sample run of your program would look like the following:
    > Enter the beginning account balance: 300.00
    > Enter the annual interest rate: 5.5
    > Enter the annual service charge: 10
    > The total interest earned is: 16.9224
    > The final account balance is: 306.922
    >
    > Here are some formulas for the quantities to be printed:
    > Total interest earned = [(1+I/12)12 - 1]*B
    > Final account balance = B + (total interest earned) - S
    >
    > Can anyone help me out with this? Thank you kindly in advance.


    No, we cannot help you here. If you need algorithms, post to newsgroup
    'comp.programming' (although I am fairly certain they won't do your
    homework for you either). Once you have the algorithm, we definitely
    can help you with C++ part, but you need to read the FAQ section 5
    first.
     
    Victor Bazarov, Mar 1, 2004
    #2
    1. Advertising

  3. savesdeday

    Mike Wahler Guest

    "savesdeday" <> wrote in message
    news:...
    > In my beginnning computer science class we were asked to translate a
    > simple interest problem. We are expected to write an algorithm that
    > gets values for the starting account balance B, annual interest rate
    > I, and annual service charge S. Your algorithm would then compute and
    > print out the total amount of interest earned during the year and the
    > final account balance at the end of the year (assuming that interest
    > is compounded monthly, and the service charge is deducted once, at the
    > end of the year). In this lab assignment you will convert this
    > algorithm into a C++ program.
    > A sample run of your program would look like the following:
    > Enter the beginning account balance: 300.00
    > Enter the annual interest rate: 5.5
    > Enter the annual service charge: 10
    > The total interest earned is: 16.9224
    > The final account balance is: 306.922
    >
    > Here are some formulas for the quantities to be printed:
    > Total interest earned = [(1+I/12)12 - 1]*B
    > Final account balance = B + (total interest earned) - S
    >
    > Can anyone help me out with this? Thank you kindly in advance.


    We can and certainly will help you with your code. As soon
    as you show it to us, and ask specific questions about it,
    that is.

    -MIke
     
    Mike Wahler, Mar 1, 2004
    #3
  4. "savesdeday" <> wrote in message
    news:...
    > In my beginnning computer science class we were asked to translate a
    > simple interest problem. We are expected to write an algorithm that
    > gets values for the starting account balance B, annual interest rate
    > I, and annual service charge S. Your algorithm would then compute and
    > print out the total amount of interest earned during the year and the
    > final account balance at the end of the year (assuming that interest
    > is compounded monthly, and the service charge is deducted once, at the
    > end of the year). In this lab assignment you will convert this
    > algorithm into a C++ program.
    > A sample run of your program would look like the following:
    > Enter the beginning account balance: 300.00
    > Enter the annual interest rate: 5.5
    > Enter the annual service charge: 10
    > The total interest earned is: 16.9224
    > The final account balance is: 306.922
    >
    > Here are some formulas for the quantities to be printed:
    > Total interest earned = [(1+I/12)12 - 1]*B
    > Final account balance = B + (total interest earned) - S
    >
    > Can anyone help me out with this? Thank you kindly in advance.


    Which parts don't you know about? The program requires you to do simple
    input, simple output and calculate a formula (I'd hesitate to call it an
    algorithm), you've even been given the formulae to use. Presumably you've
    covered all these in class. Usually its the 'putting it all together' part
    which stumps newbies.

    The best advice is simple to have a go, write some code, see if it compiles
    and if it compiles see if it runs correctly. When you have some code and you
    can't see why it isn't working, then post it here and you'll get help.

    What you won't get is people doing the work for you, that wouldn't be fair.

    john
     
    John Harrison, Mar 1, 2004
    #4
  5. Hi "savesdeday" <>

    If you were in my class, the next part of the assignment
    will ask you to extend your assignment 1 code by implement
    a checking account (which is not interest bearing) and then,
    to implement a money management account (which has a minimum
    deposit level, and has to observe a fixed withdraw date).
    In doing so, you learn OO concept of inheritance,
    overloading and overriding of functions / methods, etc.

    You were told that if you don't start your work from the 1st
    assignment, you won't be able to go further in assignment 2
    and assignment 3, as you have to add functionality to your
    own code.

    And most importantly, you were told that your fellow
    lecturers / tutors do read comp.lang.c++ several times a
    day! Don't you remember that your professors are always
    sitting in front of computers, and working so hard, you know
    now how our lives are like!

    Just joking, but I can't resist, that's such a so typical
    assignment!

    Stephen Wong @ Hong Kong

    On Mon, 1 Mar 2004, John Harrison wrote:

    >
    > "savesdeday" <> wrote in message
    > news:...
    > > In my beginnning computer science class we were asked to translate a
    > > simple interest problem. We are expected to write an algorithm that
    > > gets values for the starting account balance B, annual interest rate
    > > I, and annual service charge S. Your algorithm would then compute and
    > > print out the total amount of interest earned during the year and the
    > > final account balance at the end of the year (assuming that interest
    > > is compounded monthly, and the service charge is deducted once, at the
    > > end of the year). In this lab assignment you will convert this
    > > algorithm into a C++ program.
    > > A sample run of your program would look like the following:
    > > Enter the beginning account balance: 300.00
    > > Enter the annual interest rate: 5.5
    > > Enter the annual service charge: 10
    > > The total interest earned is: 16.9224
    > > The final account balance is: 306.922
    > >
    > > Here are some formulas for the quantities to be printed:
    > > Total interest earned = [(1+I/12)12 - 1]*B
    > > Final account balance = B + (total interest earned) - S
    > >
    > > Can anyone help me out with this? Thank you kindly in advance.

    >
    > Which parts don't you know about? The program requires you to do simple
    > input, simple output and calculate a formula (I'd hesitate to call it an
    > algorithm), you've even been given the formulae to use. Presumably you've
    > covered all these in class. Usually its the 'putting it all together' part
    > which stumps newbies.
    >
    > The best advice is simple to have a go, write some code, see if it compiles
    > and if it compiles see if it runs correctly. When you have some code and you
    > can't see why it isn't working, then post it here and you'll get help.
    >
    > What you won't get is people doing the work for you, that wouldn't be fair.
    >
    > john
    >
    >
    >
     
    Stephen S M WONG, Mar 1, 2004
    #5
  6. savesdeday

    savesdeday Guest

    "Victor Bazarov" <> wrote in message news:<GAy0c.427406$I06.4847449@attbi_s01>...
    > "savesdeday" <> wrote...
    > > In my beginnning computer science class we were asked to translate a
    > > simple interest problem. We are expected to write an algorithm that
    > > gets values for the starting account balance B, annual interest rate
    > > I, and annual service charge S. Your algorithm would then compute and
    > > print out the total amount of interest earned during the year and the
    > > final account balance at the end of the year (assuming that interest
    > > is compounded monthly, and the service charge is deducted once, at the
    > > end of the year). In this lab assignment you will convert this
    > > algorithm into a C++ program.
    > > A sample run of your program would look like the following:
    > > Enter the beginning account balance: 300.00
    > > Enter the annual interest rate: 5.5
    > > Enter the annual service charge: 10
    > > The total interest earned is: 16.9224
    > > The final account balance is: 306.922
    > >
    > > Here are some formulas for the quantities to be printed:
    > > Total interest earned = [(1+I/12)12 - 1]*B
    > > Final account balance = B + (total interest earned) - S
    > >
    > > Can anyone help me out with this? Thank you kindly in advance.

    >
    > No, we cannot help you here. If you need algorithms, post to newsgroup
    > 'comp.programming' (although I am fairly certain they won't do your
    > homework for you either). Once you have the algorithm, we definitely
    > can help you with C++ part, but you need to read the FAQ section 5
    > first.


    I'm sorry I actually did figure out the algorithm part of this
    problem. Here it is:

    Algorithm:
    Step 1 : Get a value for B, I and S
    Step 2 : Set the value of Final Balance to (1+I/12)12 B
    Step 3 : Set the value of Interest to FinalBalance – B
    Step 4 : Set the value of FinalBalance to FinalBalance – S
    Step 5 : Print the message "Interest Earned: "
    Step 6 : Print the value of Interest
    Step 7 : Print the message "Final Balance: "
    Step 8 : Print the value of FinalBalance

    I'm sorry I didnt post that earlier, still new here. Any help with the
    C++ would be appreciated. Thanks again.
     
    savesdeday, Mar 1, 2004
    #6
  7. savesdeday

    Mike Wahler Guest

    "savesdeday" <> wrote in message
    news:...
    > "Victor Bazarov" <> wrote in message

    news:<GAy0c.427406$I06.4847449@attbi_s01>...
    > > "savesdeday" <> wrote...
    > > > In my beginnning computer science class we were asked to translate a
    > > > simple interest problem. We are expected to write an algorithm that
    > > > gets values for the starting account balance B, annual interest rate
    > > > I, and annual service charge S. Your algorithm would then compute and
    > > > print out the total amount of interest earned during the year and the
    > > > final account balance at the end of the year (assuming that interest
    > > > is compounded monthly, and the service charge is deducted once, at the
    > > > end of the year). In this lab assignment you will convert this
    > > > algorithm into a C++ program.
    > > > A sample run of your program would look like the following:
    > > > Enter the beginning account balance: 300.00
    > > > Enter the annual interest rate: 5.5
    > > > Enter the annual service charge: 10
    > > > The total interest earned is: 16.9224
    > > > The final account balance is: 306.922
    > > >
    > > > Here are some formulas for the quantities to be printed:
    > > > Total interest earned = [(1+I/12)12 - 1]*B
    > > > Final account balance = B + (total interest earned) - S
    > > >
    > > > Can anyone help me out with this? Thank you kindly in advance.

    > >
    > > No, we cannot help you here. If you need algorithms, post to newsgroup
    > > 'comp.programming' (although I am fairly certain they won't do your
    > > homework for you either). Once you have the algorithm, we definitely
    > > can help you with C++ part, but you need to read the FAQ section 5
    > > first.

    >
    > I'm sorry I actually did figure out the algorithm part of this
    > problem. Here it is:
    >
    > Algorithm:
    > Step 1 : Get a value for B, I and S
    > Step 2 : Set the value of Final Balance to (1+I/12)12 B


    This step needs to be broken down into more steps.
    I.e. define how to calculate that formula.

    > Step 3 : Set the value of Interest to FinalBalance - B
    > Step 4 : Set the value of FinalBalance to FinalBalance - S


    I believe you need to think a bit more about these first four
    steps.

    > Step 5 : Print the message "Interest Earned: "
    > Step 6 : Print the value of Interest
    > Step 7 : Print the message "Final Balance: "
    > Step 8 : Print the value of FinalBalance
    >
    > I'm sorry I didnt post that earlier, still new here. Any help with the
    > C++ would be appreciated. Thanks again.


    But you haven't shown us any C++. Show us some, and we'll help
    you with it.

    Here's something to get you started:

    #include <iostream>

    double tot_interest(double balance, double rate)
    {
    double result = 0;
    /* some work for you to do here */
    return result;
    }

    double final_balance(double begin_balance,
    double total_interest,
    double service_chg)
    {
    double result = 0;
    /* some work for you to do here */
    return result;
    }

    int main()
    {
    double balance = 0;
    double rate = 0;
    double svc_charge = 0;

    std::cout << "Beginning balance: ";
    std::cin >> balance;

    std::cout << "Interest rate: ";
    std::cin >> rate;

    std::cout << "Service charge: ";
    std::cin >> svc_charg;

    std::cout << "Interest earned: "
    << tot_interest(balance, rate) << '\n';

    std::cout << "Final balance: "
    << final_balance(balance, rate, svc_charge) << '\n';

    std::cout << "Interest earned: "
    << tot_interest(balance, rate) << '\n';

    return 0;
    }

    You needn't organize your code exactly as I've done, this is
    just to give you some ideas.

    -Mike
     
    Mike Wahler, Mar 1, 2004
    #7
  8. savesdeday wrote:
    >
    > "Victor Bazarov" <> wrote in message news:<GAy0c.427406$I06.4847449@attbi_s01>...
    > > "savesdeday" <> wrote...
    > > > In my beginnning computer science class we were asked to translate a
    > > > simple interest problem. We are expected to write an algorithm that
    > > > gets values for the starting account balance B, annual interest rate
    > > > I, and annual service charge S. Your algorithm would then compute and
    > > > print out the total amount of interest earned during the year and the
    > > > final account balance at the end of the year (assuming that interest
    > > > is compounded monthly, and the service charge is deducted once, at the
    > > > end of the year). In this lab assignment you will convert this
    > > > algorithm into a C++ program.
    > > > A sample run of your program would look like the following:
    > > > Enter the beginning account balance: 300.00
    > > > Enter the annual interest rate: 5.5
    > > > Enter the annual service charge: 10
    > > > The total interest earned is: 16.9224
    > > > The final account balance is: 306.922
    > > >
    > > > Here are some formulas for the quantities to be printed:
    > > > Total interest earned = [(1+I/12)12 - 1]*B
    > > > Final account balance = B + (total interest earned) - S
    > > >
    > > > Can anyone help me out with this? Thank you kindly in advance.

    > >
    > > No, we cannot help you here. If you need algorithms, post to newsgroup
    > > 'comp.programming' (although I am fairly certain they won't do your
    > > homework for you either). Once you have the algorithm, we definitely
    > > can help you with C++ part, but you need to read the FAQ section 5
    > > first.

    >
    > I'm sorry I actually did figure out the algorithm part of this
    > problem. Here it is:
    >
    > Algorithm:
    > Step 1 : Get a value for B, I and S
    > Step 2 : Set the value of Final Balance to (1+I/12)12 B
    > Step 3 : Set the value of Interest to FinalBalance – B
    > Step 4 : Set the value of FinalBalance to FinalBalance – S
    > Step 5 : Print the message "Interest Earned: "
    > Step 6 : Print the value of Interest
    > Step 7 : Print the message "Final Balance: "
    > Step 8 : Print the value of FinalBalance
    >
    > I'm sorry I didnt post that earlier, still new here. Any help with the
    > C++ would be appreciated. Thanks again.


    So start with step 1!

    Your first 'program' would be:

    int main()
    {
    }

    compile, link it and let it run. (Yes, I recommend to run such a simple
    program. If for nothing else it is a simple test if you are familiar enough
    with your development environment).

    what was step 1?

    > Step 1 : Get a value for B, I and S


    So you need some variables, called B, I and S. What data type should
    they have? In your case it would be double, since there whole numbers
    will not be good enough (Note: floating point numbers aren't a particular
    good way to deal with moentary values, but for the moment ... )

    Thus:

    int main()
    {
    double B = 0.0, I = 0.0, S = 0.0;

    }

    compile it, link it, run it.

    Now, step 1 asks for getting *values* for B, I and S. That means
    from the user. Thus you extend your program:

    #include <iostream>

    using namespace std;

    int main()
    {
    double B = 0.0, I = 0.0, S = 0.0;

    cin >> B >> I >> S;
    }

    Again. Compile it, link it, run it. You expect your program to
    read in 3 numbers (that's what the source code tells you). But
    what happens in practice? The program waits for your input,
    you enter some numbers and then the program ends. So your next
    subgoal might be: check that the program has indeed read the numbers
    I entered:

    int main()
    {
    double B = 0.0, I = 0.0, S = 0.0;

    cin >> B >> I >> S;
    cout << "B: " << B << '\n';
    cout << "I: " << I << '\n';
    cout << "S: " << S << endl;
    }

    Again: compile it, link it, run it. Things should get more interesting
    now. The program outputs something!

    But then. Just having the program waiting for input isn't a good idea.
    At least the program could prompt for what it expects from the user:

    int main()
    {
    double B = 0.0, I = 0.0, S = 0.0;

    cout << "Please enter 3 numbers: B, I, S" << endl;

    cin >> B >> I >> S;

    cout << "B: " << B << '\n';
    cout << "I: " << I << '\n';
    cout << "S: " << S << endl;
    }

    compile it, link it, run it.

    ....
    Now you take over and write the rest of the program. Don't write
    the program in one big rush. Instead use a subgoal and try to reach
    that subgoal. Also think about ways to verify that the program is
    doing what it is supposed to do. Eg. in steap 2 the program
    will calculate something called a final balance. It is a good idea
    to output that number and use some pocket calculator to verify that
    the output number is correct.

    --
    Karl Heinz Buchegger
     
    Karl Heinz Buchegger, Mar 1, 2004
    #8
  9. savesdeday

    David Rubin Guest

    Mike Wahler wrote:

    [snip]
    > std::cout << "Beginning balance: ";
    > std::cin >> balance;


    Out of curiosity (and lazyness!), is data written to std::cout guaranteed to
    appear (on the terminal) if it is not terminated by a newline? Is this not
    similar to a common mistake in C:

    printf("Beginning balance: ");
    scanf("%lf", &balance);

    where you need to insert an fflush() statement.

    /david

    --
    Andre, a simple peasant, had only one thing on his mind as he crept
    along the East wall: 'Andre, creep... Andre, creep... Andre, creep.'
    -- unknown
     
    David Rubin, Mar 1, 2004
    #9
  10. savesdeday

    Mike Wahler Guest

    "David Rubin" <> wrote in message
    news:c2052t$...
    > Mike Wahler wrote:
    >
    > [snip]
    > > std::cout << "Beginning balance: ";
    > > std::cin >> balance;

    >
    > Out of curiosity (and lazyness!), is data written to std::cout guaranteed

    to
    > appear (on the terminal) if it is not terminated by a newline?


    Yes. See 'tie()'.

    > Is this not
    > similar to a common mistake in C:
    >
    > printf("Beginning balance: ");
    > scanf("%lf", &balance);
    >
    > where you need to insert an fflush() statement.


    No, std::cout and std::cin are guaranteed to be 'tied'
    at startup. I'll look up C&V if you like.

    -Mike
     
    Mike Wahler, Mar 1, 2004
    #10
  11. David Rubin wrote:
    > [snip]
    >> std::cout << "Beginning balance: ";
    >> std::cin >> balance;

    >
    > Out of curiosity (and lazyness!), is data written to std::cout guaranteed to
    > appear (on the terminal) if it is not terminated by a newline?


    In general case it is not guaranteed to appear. But in this particular
    case it is guaranteed to appear before program begins to wait for user
    input. The C++ standard I/O library provides means to "tie" input and
    output streams to each other. This means, among other things, that input
    request on an input stream will automatically flush the tied output
    stream (if any). By default 'std::cout' is tied to 'std::cin'.

    --
    Best regards,
    Andrey Tarasevich
     
    Andrey Tarasevich, Mar 1, 2004
    #11
  12. savesdeday

    savesdeday Guest

    This is what I have so far but there seems to be a problem because
    when I compile and run the program, the output for final balance and
    total interest are both values of 0. Please help.
    #include <iostream>
    #include <cmath>
    double tot_interest(double balance, double rate)
    {
    double result = 0;
    double tot_interest= pow (1+rate/12,12)-1*balance;
    return result;
    }

    double final_balance(double balance,
    double tot_interest,
    double svc_charg)
    {
    double result = 0;
    double final_balance=balance+tot_interest - svc_charg;
    return result;
    }
    int main()
    {
    double balance = 0;
    double rate = 0;
    double svc_charg = 0;

    std::cout << "Beginning balance: ";
    std::cin >> balance;

    std::cout << "Interest rate: ";
    std::cin >> rate;

    std::cout << "Service charge: ";
    std::cin >> svc_charg;

    std::cout << "Interest earned: "
    << tot_interest(balance, rate) << '\n';

    std::cout << "Final balance: "
    << final_balance(balance, rate, svc_charg) << '\n';

    std::cout << "Interest earned: "
    << tot_interest(balance, rate) << '\n';

    return 0;
    }
    What am I doing wrong?
     
    savesdeday, Mar 2, 2004
    #12
  13. "savesdeday" <> wrote in message
    news:...
    > This is what I have so far but there seems to be a problem because
    > when I compile and run the program, the output for final balance and
    > total interest are both values of 0. Please help.
    > #include <iostream>
    > #include <cmath>
    > double tot_interest(double balance, double rate)
    > {
    > double result = 0;
    > double tot_interest= pow (1+rate/12,12)-1*balance;


    This correctly calculates the value of the interest (I assume) and puts that
    into a variable called tot_interest.

    > return result;


    Then this returns the value of a different variable called result which has
    a value of zero.

    You need to get rid of one of the variables. It doesn't matter what the
    variable is called, but if you use one variable for the calculation then you
    use the same variable for the return.

    Like this

    {
    double tot_interest= pow (1+rate/12,12)-1*balance;
    return tot_interest;
    }

    If you like you can get rid of the variable entirely, like this

    {
    return pow (1+rate/12,12)-1*balance;
    }

    john
     
    John Harrison, Mar 2, 2004
    #13
  14. savesdeday

    Mike Wahler Guest

    "savesdeday" <> wrote in message
    news:...
    > This is what I have so far but there seems to be a problem because
    > when I compile and run the program, the output for final balance and
    > total interest are both values of 0. Please help.
    > #include <iostream>
    > #include <cmath>
    > double tot_interest(double balance, double rate)
    > {
    > double result = 0;
    > double tot_interest= pow (1+rate/12,12)-1*balance;
    > return result;
    > }


    This is what happens when you take example code, and
    try to use it without actually trying to understand it. :)

    See John's reply.

    -Mike
     
    Mike Wahler, Mar 2, 2004
    #14
  15. savesdeday

    savesdeday Guest

    "John Harrison" <> wrote in message news:<c22ovo$1p511u$-berlin.de>...
    > "savesdeday" <> wrote in message
    > news:...
    > > This is what I have so far but there seems to be a problem because
    > > when I compile and run the program, the output for final balance and
    > > total interest are both values of 0. Please help.
    > > #include <iostream>
    > > #include <cmath>
    > > double tot_interest(double balance, double rate)
    > > {
    > > double result = 0;
    > > double tot_interest= pow (1+rate/12,12)-1*balance;

    >
    > This correctly calculates the value of the interest (I assume) and puts that
    > into a variable called tot_interest.
    >
    > > return result;

    >
    > Then this returns the value of a different variable called result which has
    > a value of zero.
    >
    > You need to get rid of one of the variables. It doesn't matter what the
    > variable is called, but if you use one variable for the calculation then you
    > use the same variable for the return.
    >
    > Like this
    >
    > {
    > double tot_interest= pow (1+rate/12,12)-1*balance;
    > return tot_interest;
    > }
    >
    > If you like you can get rid of the variable entirely, like this
    >
    > {
    > return pow (1+rate/12,12)-1*balance;
    > }
    >
    > john


    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. What is the correct format to
    implement the equation [(1+I/12)12 - 1]*B (using <cmath>) ?
     
    savesdeday, Mar 3, 2004
    #15
  16. savesdeday wrote:
    >
    >
    > 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.


    What error?

    The compiler emits error messages to give you a hint on what is wrong
    in your code. Read those error messages!

    > What is the correct format to
    > implement the equation [(1+I/12)12 - 1]*B (using <cmath>) ?


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

    --
    Karl Heinz Buchegger
     
    Karl Heinz Buchegger, Mar 5, 2004
    #16
  17. savesdeday

    osmium Guest

    Karl Heinz Buchegger wrote:

    > savesdeday wrote:
    > >
    > >
    > > 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.

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

    >
    > What you have seems fine.


    I think he needs some decimal points in his code, for starters.
     
    osmium, Mar 5, 2004
    #17
  18. osmium wrote:
    >
    > Karl Heinz Buchegger wrote:
    >
    > > savesdeday wrote:
    > > >
    > > >
    > > > 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.

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

    > >
    > > What you have seems fine.

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


    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
     
    Karl Heinz Buchegger, Mar 5, 2004
    #18
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ahmed Moustafa
    Replies:
    0
    Views:
    815
    Ahmed Moustafa
    Nov 15, 2003
  2. Bapaiah Katepalli
    Replies:
    1
    Views:
    1,532
    Mike Treseler
    Jun 23, 2006
  3. someone else

    simple algorithm for finding primes

    someone else, Dec 8, 2003, in forum: C Programming
    Replies:
    32
    Views:
    1,449
    Chris Torek
    Dec 12, 2003
  4. Niu Xiao

    a simple algorithm, help!

    Niu Xiao, Dec 26, 2005, in forum: C Programming
    Replies:
    6
    Views:
    543
    Keith Thompson
    Dec 27, 2005
  5. newbie

    Simple algorithm question

    newbie, Apr 17, 2007, in forum: C++
    Replies:
    4
    Views:
    356
    red floyd
    Apr 17, 2007
Loading...

Share This Page