Writing a payroll program due next week. I'm stuck on a loop when the user enters the employee level (lines 49-57).
But ALSO, I'm stuck on the logic when I factor in this level to figure overtime hours worked. These are the levels below. But I keep going back and forth on best way to do this. Nested for sure, but how? I started something but then had to comment it out cause it wouldn't compile. Not even sure if I was going in the right direction. PLEASE HELP!
level 1 - can only work up to 20 OT hours
level 2 - up to 15 OT hours
level 3 - no OT allowed
in terms of your first question, you are using a char when you should be using an int array. A char will never equal an int unless you convert it into one. If you fix that, then working out the logic is just a simple comparison to see if they are allowed the OT based on the level. Good luck and please post any updates to the code if you still have questions.
I just reread my response so I wanted to add clarification. For level you use an array of chars. If a user enters 1, it'll actually be '1' which will never match 1. You either need to use an int arrary, or typecast level[position] to an int from a char before you do the comparison check.
A do-while loop will iterate so long as the while condition is met. Your current while condition is 1. This is interpreted by the condition as a boolean evaluation, whereby zero is false and anything non-zero is true.
Therefore, the line while( 1 ); will always evaluate to true and your loop will run indefinitely.
but it worked perfectly before I added the for loop on line 26 to be able to loop through up to 5 employees. How could that affect the nested loops? I didn't touch them. Is there a problem with a do while within a for loop?