• Status: Solved
• Priority: Medium
• Security: Public
• Views: 354

# Find the gross of an employee

Topic
Ask the user to input the number of hours a given employee has worked along with the rate of pay per hour. (make sure no one has worked more than 80 hours in a week as I think this is illegal!) Output this information along with Gross pay for this employee in a table-like output:

Hours     Rate     Gross     OverTime?
15             10  150  No
Hours  Rate  Gross  OverTime?
41  10  415  Yes

And this is my program:
#include <iostream.h>
#include <stdlib.h>
#define DEBUG_ON false

double CalcGross(double hours, double rate);

int main()
{
double rate, hours, gross;

cout <<"Enter rates: ";
cin >>rate;
cout <<"Enter hours: ";
cin >>hours;

gross = CalcGross(hours, rate);

cout<<"With "<<hours<<" hours at "<<rate;
cout << " dollars per hour, you will be paid "<<gross<<" dollars"<<endl;

system("PAUSE");
return 0;
}

double CalcGross(double hours, double rate)
/*********************************************************************
Function Name: CalcGross
Purpose: Calculates Gross from Hours and Rate.
Arguments: Hours, Rate
Returns: gross and IO include

*********************************************************************/
{
if (DEBUG_ON)
{
cout<<endl<<"CalcGross: Hours: "<<hours<< "Rate is: "<<rate;
cout<<endl;
}
if (hours > 40)
{
cout <<"Overtime: Yes ";
cout <<endl;
}
else
{
cout <<"Overtime: No ";
cout <<endl;
}

return hours * rate;
}

This program work quite right, but my teacher doesnt accepted, can someone help me to figure it out.
0
cuong5985
• 4
• 3
• 2
• +1
1 Solution

Commented:
Hi cuong5985,
> >This program work quite right, but my teacher doesnt accepted, can
> >someone help me to figure it out.
What doesn't youre teacher not accept?

Please post more specific question.

David Maisonave :-)
Cheers!
0

Author Commented:
I dont know, he already graded for me and gave me 3/10.  I wonder that i follow what he said in the topic that he gave me.  But i dont know he still gave me a bad grade, can you help me to fix it.  He doesnt gave me a comment about this, exactly i was on spring break so i cant ask him.
0

Commented:
<iostream.h> is not part of the C++ standard, so you're code is not portable.
Should use <iostream> instead, along with
using namespace std;

From reading the assignment, I think he wanted you to do error checking for correct input range at the point where you're getting the input.
Your error checking is in the CalcGross() function, and it's to late in the code to do anything about the wrong input at that point.

0

Commented:
>>Output this information along with Gross pay for this employee in a table-like output:

A table-like output would usually have a header and outlines for each column.
0

Author Commented:
Can you help me to do this, cause i just want to know so i will do it better on the test, anyway, the homework already graded?
0

Commented:
Hi cuong,

Axter is correct about iostream.h in my school teacher reduce overal score for iostream.h Use <iostream> instead.
Then points are reduces when source code is not well documented. Try put more comments inside your code. Nobody can blame you that you put there too much comments. Another points are reduces for style as output. Think bout output what your program produces an make it more nice. The last think is . When I run your program I got this error:
sh: line 1: PAUSE: command not found
then I compile it without system("PAUSE"); line and works fine. For this points can be also reduced.

good luck

./lubo
0

Commented:
here is warning what I got when compile with <iostream.h>
#warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples in clude substituting the <X> header for the <X.h> header for C++ includes, or <sst ream> instead of the deprecated header <strstream.h>.
0

Commented:
to Axter :

Axter you have very nice profile. I like it. Any hints how to becomme excelent c++ coder as you are? :-))

cheers
0

Commented:
>>Any hints how to becomme excelent c++ coder as you are? :-))

Practice, practice, practice.
0

Commented:
I might be reading wrogn here ... but it looksd like .. although you checked for OVERTIME by putting in a check for 40 HRS, I dont see any check for 80 HOURS .. as mentioned in your initial problem statement.

You are also not inputting Employee id or some info like that !!!

Other things worth noting.. from what it seems.. this should not be a simple program for multiplication of two numbers(which is what you have written) !!!

Are you sure this is not a "data structures" assignment ?

Another important aspect of becoming a GOOD programmer is "ATTENTION TO DETAIL" . I am sure AXTER would agree
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

## Featured Post

• 4
• 3
• 2
• +1
Tackle projects and never again get stuck behind a technical roadblock.