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.
OMG thank you thank you thank you! Now I see. I just added the single quotes to fix and it works. Well, I got past the loop at least. Tackling the rest now.
Stuck again :( I had the code right, but then I added the for loop to allow for up to 5 employees and now I'm stuck in the loop starting at line 33 and cant get out. Ideas?
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?
FURTHER EDIT: Still, I'd find another way to do those loops. You can avoid those break statements completely with a good while condition. It will also, in my opinion, tidy the code up considerably.