Re: I need help with my homework!! Emergency!!!

Discussion in 'C++' started by Mike, Nov 23, 2004.

  1. Mike

    Mike Guest

    "Raymond Martineau" <> wrote in message
    news:...
    > On 20 Nov 2004 18:24:42 -0800, (DaMentor) wrote:
    >
    > >Hey guys, I need help with this program. So far I've tried everything
    > >I know and can't get this thing to work properly. If someone has any
    > >suggestions please send them to me. Thanks.
    > >

    >
    > If you are asking for help on why a program isn't working, you should
    > either post an error log of the compilation process, or provide

    information
    > about why it is not working and it's expected result.
    >
    > >
    > >// Purpose: Program calculates the amount of time necessary to reach a
    > >certain
    > >// financial goal by consistantly depositing the same amount of money
    > >// into an interest-bearing account each month. The account is
    > >comounded monthly.

    >
    > For comment blocks, you should use the "/* */" comment delimiters. The
    > "//" comment delimeters are prone to wordwrapping from standard

    newsreaders
    > and will cause errors that were not present in the first place.
    >
    > >include <iostream.h>
    > >include <stdlib.h>

    >
    > Include statements should be preceeded with a "#". Even then, one of

    these
    > header files is depreciated (as stated by another poster.)
    >
    > >float months = 0;

    >
    > Why not declare this as an int instead of a float? Unless you plan to
    > expand your program to calculate daily interest, there's no reason to

    spend
    > extra cycles on calculating floating point.
    >
    > > total = total + (total * monthly_interest);

    >
    > Instead, use:
    >
    > total += total * monthly_interest;
    >
    > > months++;

    >
    > Use "++months" instead. While post-increment does work here (and isn't
    > much of a problem in C), you should change the habit for C++ as
    > post-increment is slightly less efficient when you begin to deal with
    > classes.
    >


    I've heard that said before? Why is this??
    Thanks

    Mike
    Mike, Nov 23, 2004
    #1
    1. Advertising

  2. Mike

    Phlip Guest

    Mike wrote:

    > > total += total * monthly_interest;
    > >
    > > > months++;

    > >
    > > Use "++months" instead. While post-increment does work here (and isn't
    > > much of a problem in C), you should change the habit for C++ as
    > > post-increment is slightly less efficient when you begin to deal with
    > > classes.
    > >

    >
    > I've heard that said before? Why is this??


    If you write Class::eek:perator++(int) yourself, it must return a temporary
    containing the value before incrementation.

    (The 'int' part is just a keyword re-used as a flag "I'm the post-increment
    version").

    The compiler cannot easily optimize away this temporary object.

    --
    Phlip
    http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces
    Phlip, Nov 23, 2004
    #2
    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. Gerald Klein
    Replies:
    0
    Views:
    321
    Gerald Klein
    Aug 6, 2003
  2. Ken
    Replies:
    1
    Views:
    605
    Andrew Thompson
    Jan 26, 2004
  3. Karl Heinz Buchegger

    Re: I need help with my homework!! Emergency!!!

    Karl Heinz Buchegger, Nov 23, 2004, in forum: C++
    Replies:
    1
    Views:
    379
    Raymond Martineau
    Nov 23, 2004
  4. anoosh

    Emergency Help is needed

    anoosh, Dec 12, 2007, in forum: Java
    Replies:
    6
    Views:
    354
    Mark Space
    Dec 12, 2007
  5. c676228
    Replies:
    14
    Views:
    196
    c676228
    Sep 20, 2006
Loading...

Share This Page