Simple Algorithm

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • savesdeday

    Simple Algorithm

    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.
  • Victor Bazarov

    #2
    Re: Simple Algorithm

    "savesdeday " <redhotchilica@ yahoo.com> wrote...[color=blue]
    > 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.[/color]

    No, we cannot help you here. If you need algorithms, post to newsgroup
    'comp.programmi ng' (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.


    Comment

    • Mike Wahler

      #3
      Re: Simple Algorithm


      "savesdeday " <redhotchilica@ yahoo.com> wrote in message
      news:57190a76.0 402291950.6d124 645@posting.goo gle.com...[color=blue]
      > 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.[/color]

      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


      Comment

      • John Harrison

        #4
        Re: Simple Algorithm


        "savesdeday " <redhotchilica@ yahoo.com> wrote in message
        news:57190a76.0 402291950.6d124 645@posting.goo gle.com...[color=blue]
        > 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.[/color]

        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


        Comment

        • Stephen S M WONG

          #5
          Re: Simple Algorithm

          Hi "savesdeday " <redhotchilica@ yahoo.com>

          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:
          [color=blue]
          >
          > "savesdeday " <redhotchilica@ yahoo.com> wrote in message
          > news:57190a76.0 402291950.6d124 645@posting.goo gle.com...[color=green]
          > > 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.[/color]
          >
          > 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
          >
          >
          >[/color]

          Comment

          • savesdeday

            #6
            Re: Simple Algorithm

            "Victor Bazarov" <v.Abazarov@com Acast.net> wrote in message news:<GAy0c.427 406$I06.4847449 @attbi_s01>...[color=blue]
            > "savesdeday " <redhotchilica@ yahoo.com> wrote...[color=green]
            > > 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.[/color]
            >
            > No, we cannot help you here. If you need algorithms, post to newsgroup
            > 'comp.programmi ng' (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.[/color]

            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.

            Comment

            • Mike Wahler

              #7
              Re: Simple Algorithm


              "savesdeday " <redhotchilica@ yahoo.com> wrote in message
              news:57190a76.0 402292332.6cf1c c13@posting.goo gle.com...[color=blue]
              > "Victor Bazarov" <v.Abazarov@com Acast.net> wrote in message[/color]
              news:<GAy0c.427 406$I06.4847449 @attbi_s01>...[color=blue][color=green]
              > > "savesdeday " <redhotchilica@ yahoo.com> wrote...[color=darkred]
              > > > 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.[/color]
              > >
              > > No, we cannot help you here. If you need algorithms, post to newsgroup
              > > 'comp.programmi ng' (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.[/color]
              >
              > 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[/color]

              This step needs to be broken down into more steps.
              I.e. define how to calculate that formula.
              [color=blue]
              > Step 3 : Set the value of Interest to FinalBalance - B
              > Step 4 : Set the value of FinalBalance to FinalBalance - S[/color]

              I believe you need to think a bit more about these first four
              steps.
              [color=blue]
              > 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.[/color]

              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(do uble balance, double rate)
              {
              double result = 0;
              /* some work for you to do here */
              return result;
              }

              double final_balance(d ouble 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(ba lance, rate) << '\n';

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

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

              return 0;
              }

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

              -Mike


              Comment

              • Karl Heinz Buchegger

                #8
                Re: Simple Algorithm

                savesdeday wrote:[color=blue]
                >
                > "Victor Bazarov" <v.Abazarov@com Acast.net> wrote in message news:<GAy0c.427 406$I06.4847449 @attbi_s01>...[color=green]
                > > "savesdeday " <redhotchilica@ yahoo.com> wrote...[color=darkred]
                > > > 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.[/color]
                > >
                > > No, we cannot help you here. If you need algorithms, post to newsgroup
                > > 'comp.programmi ng' (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.[/color]
                >
                > 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.[/color]

                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?
                [color=blue]
                > Step 1 : Get a value for B, I and S[/color]

                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
                kbuchegg@gascad .at

                Comment

                • David Rubin

                  #9
                  Re: Simple Algorithm

                  Mike Wahler wrote:

                  [snip][color=blue]
                  > std::cout << "Beginning balance: ";
                  > std::cin >> balance;[/color]

                  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("Beginni ng 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

                  Comment

                  • Mike Wahler

                    #10
                    Re: Simple Algorithm


                    "David Rubin" <noname@nowhere .net> wrote in message
                    news:c2052t$6lt @netnews.proxy. lucent.com...[color=blue]
                    > Mike Wahler wrote:
                    >
                    > [snip][color=green]
                    > > std::cout << "Beginning balance: ";
                    > > std::cin >> balance;[/color]
                    >
                    > Out of curiosity (and lazyness!), is data written to std::cout guaranteed[/color]
                    to[color=blue]
                    > appear (on the terminal) if it is not terminated by a newline?[/color]

                    Yes. See 'tie()'.
                    [color=blue]
                    > Is this not
                    > similar to a common mistake in C:
                    >
                    > printf("Beginni ng balance: ");
                    > scanf("%lf", &balance);
                    >
                    > where you need to insert an fflush() statement.[/color]

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

                    -Mike


                    Comment

                    • Andrey Tarasevich

                      #11
                      Re: Simple Algorithm

                      David Rubin wrote:[color=blue]
                      > [snip][color=green]
                      >> std::cout << "Beginning balance: ";
                      >> std::cin >> balance;[/color]
                      >
                      > 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?[/color]

                      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

                      Comment

                      • savesdeday

                        #12
                        Re: Simple Algorithm

                        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(do uble balance, double rate)
                        {
                        double result = 0;
                        double tot_interest= pow (1+rate/12,12)-1*balance;
                        return result;
                        }

                        double final_balance(d ouble balance,
                        double tot_interest,
                        double svc_charg)
                        {
                        double result = 0;
                        double final_balance=b alance+tot_inte rest - 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(ba lance, rate) << '\n';

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

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

                        return 0;
                        }
                        What am I doing wrong?

                        Comment

                        • John Harrison

                          #13
                          Re: Simple Algorithm


                          "savesdeday " <redhotchilica@ yahoo.com> wrote in message
                          news:57190a76.0 403021142.11b21 58a@posting.goo gle.com...[color=blue]
                          > 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(do uble balance, double rate)
                          > {
                          > double result = 0;
                          > double tot_interest= pow (1+rate/12,12)-1*balance;[/color]

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

                          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


                          Comment

                          • Mike Wahler

                            #14
                            Re: Simple Algorithm


                            "savesdeday " <redhotchilica@ yahoo.com> wrote in message
                            news:57190a76.0 403021142.11b21 58a@posting.goo gle.com...[color=blue]
                            > 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(do uble balance, double rate)
                            > {
                            > double result = 0;
                            > double tot_interest= pow (1+rate/12,12)-1*balance;
                            > return result;
                            > }[/color]

                            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


                            Comment

                            • savesdeday

                              #15
                              Re: Simple Algorithm

                              "John Harrison" <john_andronicu s@hotmail.com> wrote in message news:<c22ovo$1p 511u$1@ID-196037.news.uni-berlin.de>...[color=blue]
                              > "savesdeday " <redhotchilica@ yahoo.com> wrote in message
                              > news:57190a76.0 403021142.11b21 58a@posting.goo gle.com...[color=green]
                              > > 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(do uble balance, double rate)
                              > > {
                              > > double result = 0;
                              > > double tot_interest= pow (1+rate/12,12)-1*balance;[/color]
                              >
                              > This correctly calculates the value of the interest (I assume) and puts that
                              > into a variable called tot_interest.
                              >[color=green]
                              > > return result;[/color]
                              >
                              > 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[/color]

                              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>) ?

                              Comment

                              Working...