I am looking for help with my class assignment for C Programming. I need to write a program that will calculate weekly pay for employees.
For each employee the program should prompt the user to enter the clock number, wage rate, and number of hours. The clock number is a unique identifier for an employee, the wage rate is the hourly rate the employee is paid, and hours is how many hours an employee worked within a given week. The program determines the gross pay and outputs the following
Clock# Wage Hours Gross
098401 10.60 51.0 540.60
Column alignment, leading zeros in Clock#, and zero suppression in float fields are important. Remember that you cannot type in 098401 (its Octal, and invalid as well) ... type in as 98401 and use print formatting to print as 098401. Assume that clock numbers are at a most 6 digits long, and pad with leading zeros if less than 6 digits.
Use the following data as test input:
Clock# Wage Hours
98401 10.60 51.0
526488 9.75 42.5
765349 10.50 37.0
34645 12.25 45.0
127615 8.35 0.0
The program should query the user for how many sets of test data (i.e., employees to process), and loop that many times. In our example above, you would enter the number 5, as there would be 5 employees to process.
Don't expect a nice output that shows all the employee data in a one table. Its OK to have your output show the prompts for data on the first employee, print information about that employee, prompt for information about the next employee, print info on that next employee, and so one until each employee data set is processed.
You will run this program ONE time as stated before, and you will initially prompt the user for the number of data sets to process (such as 5) that you will incorporate into your loop test.© BrainMass Inc. brainmass.com June 19, 2018, 10:10 pm ad1c9bdddf
I suspect the help you need with this program is about how to format output in the C language. I will get to that in a moment.
The first thing the program will need to do is prompt the user to enter how many employees to process. After reading that input from the user, it will have to perform all the operations for each employee. That implies a loop of some kind. Since the assignment is to loop a given number of times (the number that was entered by the user), a for loop seems reasonable. Something like this:
for (i=0; i<numberOfEmployeesToProcess; i++)
/* THIS IS WHERE ALL THE CODE TO PROCESS EACH
** EMPLOYEE WOULD GO
For each employee entered, the program has to prompt for, and read, three values, the
clock number, wage rate, and number of hours. A prompt is really just a function call to "printf" followed by a function call to "scanf". The printf function prints the information you want to ask the user, like: "Please enter the social security number 1: ". To get printf to actually print that, you would call it like this:
int i = 1;
printf ("Please enter the social security number %.1d: ", i);
That %d is very important for printf. The way the function works is to substitute things for what appears after the "%". There's a whole bunch of things it does, and that's what you'll need to use to format the output nicely. In this particular case, I'm telling printf to substitute the value in the variable "i" for the %d. Given the way I've just called it, the result should be the same as the prompt in the paragraph above that code. Please note that the ".1" following the percent sign tells the function to only print one digit of the number. If the variable had the value 333 stored in it, the only thing you would see would be this: "Please enter the social security number 3: ". If, however, you called printf like this:
printf ("Please enter the social security number %.4: ", i);
And the value of i at that point was still 333, it would print: "Please enter the social security number 333: ". There are a variety of things the printf function can do with it's formatting. The basics of it are as follows:
The first argument to printf is a character string that may or ...
This (approximately) 1,600 word document will describe the use of the control and substitution characters used with printf and scanf to read and write formatted I/O in the C language.