• 10-14-2001
taurusborn
Hey guys I need to combine the following into one if statement:

else if (hrs >= 40.01)
{
salary = hrs * payrt * 1.5;
cout << "\nYour gross pay for the week is " << setw(1) << ":"
<< setw(8) << salary << endl;
}

else if (hrs <= 59.99)
{
salary = hrs * payrt * 1.5;
cout << "\nYour gross pay for the week is " << setw(1) << ":"
<< setw(8) << salary << endl;
}

I tried: else if (hrs >= 40.01 || <= 59.99) but it didnt work. Thanx for your help.

N.B. this is just part of my program, I also found the hours worked over 60 hrs and hours worked under 40 hrs. This is only part that goes crazy once its ran, so I am trying to combine the two if statements.:cool:
• 10-14-2001
*pointer
>else if (hrs >= 40.01 || <= 59.99)
That won't work, what are you testing the second condition on? You assumed it would test the condition on hrs, but in this game you can't assume anything or you'll get burned ;)
Code:

```else if ( hrs >= 40.01 || hrs <= 59.99 ) {     .     .  // Do stuff     . }```
BTW, combining the two statements will perform exactly the same, so your "going crazy" could very well be caused by something else. Though repetition is bad in coding and using one test to do the same thing instead of two tests will save you heartache in debugging.
• 10-14-2001
Brown Drake
Quote:

Originally posted by taurusborn
Hey guys I need to combine the following into one if statement:

else if (hrs >= 40.01)
{
salary = hrs * payrt * 1.5;
cout << "\nYour gross pay for the week is " << setw(1) << ":"
<< setw(8) << salary << endl;
}

else if (hrs <= 59.99)
{
salary = hrs * payrt * 1.5;
cout << "\nYour gross pay for the week is " << setw(1) << ":"
<< setw(8) << salary << endl;
}

Maybe try:
else if (hrs > 40 && hrs < 60)
{
.
.
.
}
• 10-14-2001
taurusborn
Thanx
Thanx a million guys, my program now works, you guys rock!!!:D