QuestionQuestion

Transcribed TextTranscribed Text

PROGRAM LOOPING QUESTIONS Write a C program that will calculate the pay for employees. For each employee the program should prompt the user to enter the clock number, wage rate, and number of hours. This input will be used to determine the gross pay for a given week, which is the number of hours worked in a given week multiplied by the an employee's hourly wage. Use the following data as test input for clock number, wage, and hours. Clock Wage Hours ------ ---- ----- 98401 10.60 51.0 526488 9.75 42.5 76534910.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 there are, and loop that many times. See the "prompt" code example in the lecture notes on the For Loop for details on how to do this. Do not expect a nice output that shows all the employee data in a one table. It is 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 and as stated before ... so one will need to initially prompt the user for the number of data sets to process ... which you can then incorporate into your loop test. Below are some additional items to keep in mind when doing this assignment: 1. Assume that clock numbers are at most 6 digits long and pad with leading zeros when printing if less than 6 digits. 2. Understand that you can't type in the leading zeros for your input, for example, typing in 098401 results in that number being known to the compiler as an Octal number (recall it starts with a zero), and worst, it is invalid because it contains the digits 8 and 9 (only 0-7 are valid). Type in the number 98401 and print with leading zeros to get around this issue. See the "Sample Output" section below to better illustrate what I am requesting. 3. Zero suppression of float fields is important, use the formatting syntax shown in your lecture notes. For example, show just two digits past the decimal point for money fields such hourly wage and gross pay, and only a single digit pass the decimal for the hours field. Without any formatting, the output will show the default of six decimal places (such as: 51.000000 or 551.274321) which does not make for readable output. 4. Do not use any material from any chapters beyond this week's lecture notes. I realize you could use advanced topics like arrays, pointers, linked lists, strings, structures, and functions ... but part of the challenge is using only what we covered so far. Rest assured that future homeworks will incorporate all these advanced topics in the weeks that follow. 5. You may use file pointers if you wish, but it is purely optional. Doing so will allow you to print the output in the advanced manner shown in the last section at the end of this page. See the coding template provided in the lecture note that follows to get started with this option. Sample Output - Assignment 1 Option 1 - Typical Run Session (not using IDEOne) Here is sample output that would display from a standard compiler you would have installed on your computer. The items in blue indicate the values you would have to type onto the screen when prompted by your program, while the output generated by your program is shown in purple. ***Pay Calculator*** Enter number of employees to process: 5 Enter Employee's Clock #: 98401 Enter hourly wage: 10.60 Enter number of hours worked: 51.0 ----------------------------------------- Clock# Wage Hours Gross ----------------------------------------- 098401 10.60 51.0 540.60 Enter Employee's Clock #: 526488 Enter hourly wage: 9.75 Enter number of hours worked: 42.5 ----------------------------------------- Clock# Wage Hours Gross ----------------------------------------- 526488 9.75 42.5 414.38 Enter Employee's Clock #: 765349 Enter hourly wage: 10.50 Enter number of hours worked: 37.0 ----------------------------------------- Clock# Wage Hours Gross ----------------------------------------- 765349 10.50 37.0 388.50 Enter Employee's Clock #: 34645 Enter hourly wage: 12.25 Enter number of hours worked: 45.0 ----------------------------------------- Clock# Wage Hours Gross ----------------------------------------- 034645 12.25 45.0 551.25 Enter Employee's Clock #: 127615 Enter hourly wage: 8.35 Enter number of hours worked: 0.0 ----------------------------------------- Clock# Wage Hours Gross ----------------------------------------- 127615 8.35 0.0 0.00 Option 2 - If using IDEOne If you use IDEOne, you must enter all input items up front, locating them in its "stdin" area. Below is the set of sample inputs you are welcome to use. This example is telling the program to "process 5 employees", and then provides the Clock Number, Hourly Wage, and Number of Hours worked for each of the 5 employees. Data is normally delimited by either a blank space or new line for the scanf statement in your program to work correctly. 5 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 If you use IDEOne, you will not see input values after each prompt because all data is entered up front. With other compilers (see previous example), you will be entering those values in real time. Here is sample IDEOne output that would display. ***Pay Calculator*** Enter number of employees to process: Enter Employee's Clock #: Enter hourly wage: Enter number of hours worked: ----------------------------------------- Clock# Wage Hours Gross ----------------------------------------- 098401 10.60 51.0 540.60 Enter Employee's Clock #: Enter hourly wage: Enter number of hours worked: ----------------------------------------- Clock# Wage Hours Gross ----------------------------------------- 526488 9.75 42.5 414.38 Enter Employee's Clock #: Enter hourly wage: Enter number of hours worked: ----------------------------------------- Clock# Wage Hours Gross ----------------------------------------- 765349 10.50 37.0 388.50 Enter Employee's Clock #: Enter hourly wage: Enter number of hours worked: ----------------------------------------- Clock# Wage Hours Gross ----------------------------------------- 034645 12.25 45.0 551.25 Enter Employee's Clock #: Enter hourly wage: Enter number of hours worked: ----------------------------------------- Clock# Wage Hours Gross ----------------------------------------- 127615 8.35 0.0 0.00 Advanced Output Display (optional with file pointers) Here is an advanced way to present the information if you decide to use file pointers (optional) and create an output file that only presents the actual data values, instead of also displaying all the input prompts. In other words, you get a "cleaner" output. You can only get this type of output if you use "File Pointers" that I presented in the looping notes. Doing this is purely optional and will not result in any additional points, yet is a good way to challenge yourself. Please note that you can not use file pointers with IDEOne ... it does not support it because it will not let you write a file in its cloud environment. Understand in this scenario, you still prompt for values, it is just that they will show up on the screen (which in C terms is called: stdin), while the items below will be routed to a designated output file on your computer ... thanks to using your output file pointer. Clock Wage HoursGross Pay ------ ---- ----- 098401 10.60 51.0 526488 9.75 42.5 765349 10.50 37.0 034645 12.25 45.0 127615 8.35 0.0 -------- 540.60 414.38 388.50 551.25 0.00

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include <stdio.h>
int main(void)
{
    int loopInd;      /* The for loop's index value*/
int noOfEmps;    /* The number of employees being entered */
int clockNo;    /* The employee's clock number */
float wage;      /* The employee's wage per hour */
float hours;    /* The employee's hours worked */
float grossPay; /* The employees gross pay */

// Header print out
printf("***Pay Calculator***");

printf("\n\nEnter the number of employees to process: ");
scanf("%d",&noOfEmps);


    for(loopInd=1;loopInd<=noOfEmps;++loopInd)
    {
    /* Enter values needed to determine gross pay */
    printf("\nEnter Employee's Clock #: ");
    scanf("%d",&clockNo);
    printf("Enter hourly wage: ");
    scanf("%f",&wage);
    printf("Enter the number of hours worked: ");
    scanf("%f",&hours);
    /* calculate gross pay earned */
    grossPay = wage * hours;

/* print the employee's pay stub to the screen */
printf("\n-----------------------------------");
printf("\nClock# Wage Hours Gross");
printf("\n-----------------------------------");...

By purchasing this solution you'll be able to access the following files:
Solution.docx.

$6.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats