OK, there's a start.
Originally Posted by edesign
Now imagine you're the paymaster at the small company of ten employee's, and you are figuring this out, by hand.
Since each employee will have an employee number > 0, I would use that as a test condition for your first while loop:
If you break the pay down, into small parts (regular, ot_pay, full pay), then it's just easier
employee_no = 1 /* otherwise the while loop is entirely skipped, perhaps */
while(employee_no > 0)
ot = 0, work hours = 0, regular pay = 0, ot_pay = 0, full pay = 0, employee = 0
print a prompt for what to enter, and then input their employee number
if(employee number == 0)
Without the continue (or break), you'll be asked to fill in all the data for the employee with
the zero employee number, which you don't want. The "continue" just moves control to
the very bottom of the loop, which will then bring control right to the test at the top of the
while loop, which employee number 0 will fail, and then break out of the loop, completely.
print a prompt for no. of hours, and input that integer since no fractions of hours allowed.
calculate overtime hours:
if work hours > 40
then ot = work hours - 40
regular pay = 8 * work hours
if(ot > 0)
ot_pay = 12 * OT (12 * each hour of overtime)
full pay = regular pay + ot_pay
print employee no., regular pay, ot_pay, and full pay
And loop back up.
to make up the logic for it, and it's easier to troubleshoot it when there's a problem.
<Apologies, I got into the logic, and didn't notice the "the overtime" part of the problem.>
All those sets at the top of the loop may seem unneeded, but variables like that in a loop, can give you the craziest errors.
Code this up, and step through it several times. See if I've made any errors!
Change it around a bit, as you like. See if that new version's logic is good or not.
Most of us learn best by doing, not by just reading about it.