Learn how to a build a cloud-first strategyRegister Now


Find the gross of an employee

Posted on 2005-04-15
Medium Priority
Last Modified: 2010-04-01
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;

      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;
    if (hours > 40)
         cout <<"Overtime: Yes ";
         cout <<endl;
         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.
Question by:cuong5985
  • 4
  • 3
  • 2
  • +1
LVL 30

Expert Comment

ID: 13793109
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 :-)

Author Comment

ID: 13793143
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.
LVL 30

Expert Comment

ID: 13793212
<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.

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 30

Expert Comment

ID: 13793236
>>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.

Author Comment

ID: 13793252
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?
LVL 10

Expert Comment

ID: 13795390
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

LVL 10

Expert Comment

ID: 13795401
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 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>.
LVL 10

Expert Comment

ID: 13795439
to Axter :

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

LVL 30

Expert Comment

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

Practice, practice, practice.

Accepted Solution

waseemanis earned 150 total points
ID: 13831959
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question