Develop a program that will determine the gross pay for each of several employees. The
company pays “straight time” for the first 40 hours worked by each employee and pays
“time-and-a-half” for all hours worked in excess of 40 hours. You are given a list of the
employees of the company, the number of hours each employee worked last week and the
hourly rate of each employee. Your program should input this information (no name,
though) for each employee and should determine and display the employee’s gross pay. You
should also put a check in for any employee who exceeds 80 hours. When this happens, you
should print a message saying, “Who are you kidding? Go see the boss!” Here is sample
output.

## All 6 Replies

So what is your question, exactly?

I have no clue where to begin?

Could someone give me a hint how to correct please? This is what I did so far thank you!

``````/* February 16, 2008 */
/* This program will determine the gross pay for each employee. */

#include <stdio.h>

int main(void)
{

/* Declare variables */

float salary;    		/* salary pay */
int hours;    		/* hours worked */
float rate;     		/* hourly wage */
float overt=1.5; 		/*over time rate*/

/* Prompt for input values from the screen */

/*... use printf and scanf here*/
printf("Enter number of worked hours: ");
scanf("%f", &hours);
printf("Enter the rate: ");
scanf("%f", &rate);

/* calculate gross pay */
salary = rate * hours;

/*... now print out to the screen using printf (ie, print the value) */

printf("Salary is %f.\n", rate);
} /* end of main */``````

Well there a bunch of ways to do it. Are you typing in each employee's hours and wage rate or are you reading from a file? Are you collecting and storing each employee's data, then immediately figuring out the math and displaying it, or do you need to store all of it, then process all of it. If the latter, you would need to use an array. If the former, a single variable for hours and a single variable for array is sufficient, I think. Do you know how many employees there are ahead of time? You are going to have to have some type of loop that you'll go through once for each employee. What kind of loop you choose will depend on some of the answers to these questions. You can use "if" statements to check for whether an employee has worked for more than 40 or 80 hours.

I would first figure out the answers to the above, particularly whether/when/how you know when there are no more employees (end of input file, the person types in that there are no more, or the person types in ahead of time how many people). The answer to that will help you decide what type of loop to use.

I’m collecting and storing each employee’s data, then immediately figuring out the math and displaying it on the screen. For example, something like this

Enter # of hours worked (-1 to end): 41
Enter hourly rate of the worker (\$00.00): 10.00
Salary is \$415.00

Okay, then no array is needed. You are having the user input the data so no file needs to be read. Also, I see that the person enters -1 to signify the end of the data. Therefore you don't know ahead of time how many employees there are. Given that, in my opinion, a while-loop would make more sense than a for-loop. You could have either a Do-While loop or a While loop. It's a matter of personal preference.

You could use functions to help you. It's short enough that you may not really need them. Personally I would not bother with them unless you are required to have them. So I would figure out what you have to do each time and put that code inside the loop. Figure out what can stay outside the loop and what can't. Your loop control variable could be the number of hours worked. You'll compare that to -1 to decide whether to continue going through the loop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.