C++ Formula Error - Confusing Output
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: C++ Formula Error - Confusing Output

  1. #1
    Join Date
    Feb 2011
    Posts
    4

    Question C++ Formula Error - Confusing Output

    I have attached the c++ code file and the header file I'm using to compile it.
    The program has to take in employee details, and work out a wage slip from there.
    The problem is from line 112 - 120, when the hours & overtime must be entered together.
    Any hours over 37.5 need to be separated and declared as a separate variable. Then multiplied by the rate of pay. The variables must be declared separately because they are both used separately, they go on to multiply by separate rate of pay, the output for this is also spewed out like garbage! Apart from that the program runs fine and put out all the right figures.
    Any help will be greatly appreciated!


    if ( customers[row].hours < 37.5 )
    {
    customers[row].ohours = customers[row].hours - 37.5;
    customers[row].hours = 37.5;
    }
    else if (customers[row].hours > 37.5 )
    {
    customers[row].hours = customers[row].hours;
    customers[row].ohours = 0;
    }
    Attached Files Attached Files

  2. #2
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,637

    Re: C++ Formula Error - Confusing Output

    I didn't look at your attachments, but ...

    say 40 hours are worked ... what will your code calculate for
    ohours and hours ?

    Also, what if the number of hours is exactly 37.5 ?

  3. #3
    Join Date
    Feb 2011
    Posts
    4

    Re: C++ Formula Error - Confusing Output

    if 40 hours are worked, it should calculate 37.5 at normal rate and 2.5 at overtime rate of time and a half.
    if 37.5 hours are worked it should just calculate 37.5 * rate. However if 38 are worked, 0.5 hours should be paid at the overtime rate.

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,196

    Re: C++ Formula Error - Confusing Output

    I'm thinking you should examine your use of < and >

  5. #5
    Join Date
    Feb 2011
    Posts
    4

    Cool Re: C++ Formula Error - Confusing Output

    Didn't even notice that! Silly error.

    Corrected it:-

    if ( customers[row].hours >= 37.5 )
    {
    customers[row].ohours = customers[row].hours - 37.5;
    customers[row].hours = 37.5;
    }
    else if (customers[row].hours < 37.5 )
    {
    customers[row].hours = customers[row].hours;
    customers[row].ohours = 0;
    }

    But there still seems to be some problem with the calculations in the next few line and im getting -1.07374e+008 out of both calculations.

    customers[row].rateo = (customers[row].rate*1.5);

    customers[row].spay = (customers[row].hours*customers[row].rate);
    customers[row].opay = (customers[row].ohours*customers[row].rateo);

    rate being the input value per hour
    and rateo being the overtime value at time+1/2.

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,196

    Re: C++ Formula Error - Confusing Output

    Look at all the values in your calculation and figure out which one doesn't make sense. Your debugger will help.

  7. #7
    Join Date
    Feb 2011
    Posts
    4

    Re: C++ Formula Error - Confusing Output

    i was passing [row] instead of [r]. [row] is an empty field!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center