Sentinel Assistance

One is to write program to read a collection of employee data (hours and rate) entered at the terminal and to calculate and display the gross pay for each employee. The program should stop when the user enters a sentinel value of -0 for hours.

I just wanted help as to where I should start with this, because I'm utterly lost.
Last edited on
You could approach this by gradually building towards the full functionality.

To begin with, write a program to get the data for just one employee.

When you have the data, calculate and display the gross pay.

From there you can look at enclosing the relevant part of your code in a loop.

One step at a time, start simple, and gradually enhance what you have.
Ok. This is what i came up with. Is this right?

int hrs,rate,grossPay;

cout<<"Please type hours worked :"<<endl;
cout<<"What is your hourly rate?"<<endl;
if (hrs > 0)
cout<<"your gross pay is $" <<grossPay<<endl;
else if(hrs <=0)
That looks reasonable. I would think it better to use type double rather than int as the hours might perhaps have a 0.5 and the hourly rate I'd expect might also have a decimal part.

Of course it needs the usual #include headers and function main()

A minor point, there are braces { } around the if-else which don't seem to serve any purpose, I would remove them.

When you have the above working to your satisfaction, you could wrap the statements from the first cout to the last cout inside a loop.

Maybe something like this:
    while (true)
        // your code here

Now that loop will repeat forever. So you need some way to escape from the loop. After getting the value of rate from the user, insert a couple of lines like this:
        if (rate == 0)
Last edited on
Thank you for your input, it was greatly appreciated.
Topic archived. No new replies allowed.