### Employee Loop Problem

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758`` ``````#include #include using namespace std; int main () { float payrate,hours,grosspay,OT; for (int x=1 ; x<=3; x++) { cout << "\nFor employee "<> payrate; while(payrate < 5.75 || payrate > 34.75) { cout << "\n\tError: pay rate is out of bounds!"; cout <<"\n\tEnter the payrate for the this employee: "; cin >>payrate; } cout <<"\nEnter the hours worked for this employee: "; cin >> hours; while(hours < 0 || hours > 80) { cout <<"\n\tError: hours is out of bounds!"; cout<<"\n\tENter the hours worked for this employee: "; cin >>hours; } if(hours<=40.0f) grosspay=hours*payrate; else if(hours<=60.0f) grosspay=40.0f*payrate+1.5f*payrate*(hours-40.0f); else grosspay=80.0f*+2.0f*payrate*(hours-60.0f); cout <<"\nfor employee "<

this is a program that is supposed to take the values of 3 employees and calculate their gross pay. i have a question

how do i designate my program so that when i try to display three different outputs for 3 different employee it doesn't try to reuse the first variable enter and calculated (i.e hours payrate and gross pay). when i code out an output, it doesnt account for the different numbers entered within each loop.
If you want to store more data then you need more variables. If you don't know how to use objects yet then we'll skip that part (but keep this example in mind for when you start to learn them). You should change your variables into array's.
that is what my teacher had said but he wants us to hold off on using arrays becasue he wants us to see the difference in why not using arrays is so clunky
Ah, you have one of those teachers, tell them that I said he can't retire soon enough. If that's the case though, you just have to be verbose about it. Declare your variables: payrate1, payrate2, payrate3, hours1, hours2, hours3 ... etc. Then you have to prompt the user to input payrate1, payrate2 ... you get the idea. Honestly I've always viewed excercises like this to be a step backward, they don't actually teach you anything and only serve to show you that it's still possible to do things wrong.
 that is what my teacher had said but he wants us to hold off on using arrays becasue he wants us to see the difference in why not using arrays is so clunky

Could be worse. Like if he was a Driver's Ed teacher who made his students stop the car by slamming into a tree so that next week they can see how much better it is to use the brake pedal.
Topic archived. No new replies allowed.