08.01.2023 Views

Learn to Program with C_ Learn to Program using the Popular C Programming Language ( PDFDrive )

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 5 ■ Programs with Repetition Logic

In order to show you another way to read a string, we will assume that the data is stored in the

file as follows:

Maggie May 50 12.00

Akira Kanda 40 15.00

Richard Singh 48 20.00

Jamie Barath 30 18.00

END

We use the “first name” END as the end-of-data marker.

Regular pay, overtime pay, and net pay will be calculated as described in Section 4.4.1. The

employee name, hours worked, rate of pay, regular pay, overtime pay, and net pay are printed

under a suitable heading. In addition, we will write the program to do the following:

• Count how many employees are processed.

• Calculate the total wage bill (total net pay for all employees).

• Determine which employee earned the highest pay and how much. We will

ignore the possibility of a tie.

For the sample data, the output should look like this:

Name Hours Rate Regular Overtime Net

Maggie May 50.0 12.00 480.00 180.00 660.00

Akira Kanda 40.0 15.00 600.00 0.00 600.00

Richard Singh 48.0 20.00 800.00 240.00 1040.00

Jamie Barath 30.0 18.00 540.00 0.00 540.00

Number of employees: 4

Total wage bill: $2840.00

Richard Singh earned the most pay of $1040.00

An outline of the algorithm for reading the data is as follows:

read firstName

while firstName is not "END" do

read lastName, hours, rate

do the calculations

print results for this employee

read firstName

endwhile

We will use the specification %s in fscanf for reading the names. Suppose we have declared

firstName as

char firstName[20];

113

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!