Write a program to process weekly employee time cards for all employees of an organization. Each employee will have three data items: the employee's name, the hourly wage rate, and the number of hours worked during a given week. Employees are to be paid time-and-a-half for all hours worked over 40. A tax amount of 3.625 percent of gross salary will be deducted. The program output should show each employee's name, gross pay, and net pay, and should also display the total net and gross amounts and their averages. Use zzzzzz as a sentinel value for name.
My problem is that ive written a code but i want the program to terminate once the user types in "zzzzzz" but for some reason it goes through the loop one more time and messes up my averages. any help here?
The program should immediately break out of the loop if the sentinel value is entered, so you should check for it straight after cin >> name and break the loop right there and then. Also, zzzzzz is a terrible sentinel value. If any other number of z letters are entered, then it won't break the loop. Why not a sentinel value of "quit" or something else sensible?
Even if the user has input the sentinel value, the while loop proceeds because we has already entered the block of while loop. The condition of while loop will not be checked at that point.
To make it not go through if the sentinel value is input, you can simply make use of an if statement, if (name != Sentinel) and then use a block for all code thereafter in the while loop.
Note that you should place the counter increment, counter++ in that if code block.
Otherwise, you will make an off-by-one error.
@Mats sadly, my im in a beginner's c++ class and the instructor has specifically asked us to make zzzzzz the sentinel value. And as to both of your replies, THANK YOU SO MUCH. I couldnt figure that problem out for the life of me and you guys broke it down so simply. i owe you guys.