I am using this if statement to formulate some sort of output however only the last block executes where each if is suppose to execute depending on the gross pay that will determine the tax.

It reading input using fstream from a .txt file It reading the right numbers

The if statement is working correctly so its screwing up my output

{
    if (gross1, gross2, gross3, gross4, gross5 < THREE_HUNDRED){
               tax = TAX1; 
               taxdeduct = (tax /100); 
               taxamount = gross1*taxdeduct, taxamount = gross2*taxdeduct, taxamount = gross3*taxdeduct, taxamount = gross4*taxdeduct, taxamount = gross5*taxdeduct;
               net1 = gross1-taxamount, net2 = gross2-taxamount, net3 = gross3-taxamount, net4 = gross4-taxamount, net5 = gross5-taxamount;
               
               cout<<fixed<<showpoint;
               cout<<setprecision(2);
               cout<<hours1<<setw(12)<<rates1<<setw(11)<< gross1<<setw(6)<<tax<<setw(12)<<net1<<endl; 
               cout<<hours2<<setw(12)<<rates2<<setw(11)<<gross2<<setw(6)<<tax<<setw(12)<<net2<<endl; 
               cout<<hours3<<setw(12)<<rates3<<setw(11)<<gross3<<setw(6)<<tax<<setw(12)<<net3<<endl;; 
               cout<<hours4<<setw(12)<<rates4<<setw(11)<<gross4<<setw(6)<<tax<<setw(12)<<net4<<endl; 
               cout<<hours5<<setw(12)<<rates5<<setw(11)<<gross5<<setw(6)<<tax<<setw(12)<<net5<<endl;
               } 
     if (gross1, gross2, gross3, gross4, gross5 >= THREE_HUNDRED && gross1, gross2, gross3, gross4, gross5 < FOUR_HUNDRED){
               tax = TAX2; 
               taxdeduct = (tax /100); 
               taxamount = gross1*taxdeduct, taxamount = gross2*taxdeduct, taxamount = gross3*taxdeduct, taxamount = gross4*taxdeduct, taxamount = gross5*taxdeduct;
               net1 = gross1-taxamount, net2 = gross2-taxamount, net3 = gross3-taxamount, net4 = gross4-taxamount, net5 = gross5-taxamount;
               
               cout<<fixed<<showpoint;
               cout<<setprecision(2);
               cout<<hours1<<setw(12)<<rates1<<setw(11)<< gross1<<setw(6)<<tax<<setw(12)<<net1<<endl; 
               cout<<hours2<<setw(12)<<rates2<<setw(11)<<gross2<<setw(6)<<tax<<setw(12)<<net2<<endl; 
               cout<<hours3<<setw(12)<<rates3<<setw(11)<<gross3<<setw(6)<<tax<<setw(12)<<net3<<endl;; 
               cout<<hours4<<setw(12)<<rates4<<setw(11)<<gross4<<setw(6)<<tax<<setw(12)<<net4<<endl; 
               cout<<hours5<<setw(12)<<rates5<<setw(11)<<gross5<<setw(6)<<tax<<setw(12)<<net5<<endl; 
               }
    if (gross1, gross2, gross3, gross4, gross5 >= FOUR_HUNDRED){
               tax = TAX3; 
               taxdeduct = (tax /100); 
               taxamount = gross1*taxdeduct, taxamount = gross2*taxdeduct, taxamount = gross3*taxdeduct, taxamount = gross4*taxdeduct, taxamount = gross5*taxdeduct;
               net1 = gross1-taxamount, net2 = gross2-taxamount, net3 = gross3-taxamount, net4 = gross4-taxamount, net5 = gross5-taxamount;
               
               cout<<fixed<<showpoint;
               cout<<setprecision(2);
               cout<<hours1<<setw(12)<<rates1<<setw(11)<< gross1<<setw(6)<<tax<<setw(12)<<net1<<endl; 
               cout<<hours2<<setw(12)<<rates2<<setw(11)<<gross2<<setw(6)<<tax<<setw(12)<<net2<<endl; 
               cout<<hours3<<setw(12)<<rates3<<setw(11)<<gross3<<setw(6)<<tax<<setw(12)<<net3<<endl;; 
               cout<<hours4<<setw(12)<<rates4<<setw(11)<<gross4<<setw(6)<<tax<<setw(12)<<net4<<endl; 
               cout<<hours5<<setw(12)<<rates5<<setw(11)<<gross5<<setw(6)<<tax<<setw(12)<<net5<<endl; 
               }
}

>>if (gross1, gross2, gross3, gross4, gross5 < THREE_HUNDRED){

That is not the right way to code it. The compiler doesn't complain because its syntaticlly correct -- the comma operator says only gross5 is compared to THREE_HUNDRED

Correct the problem like this: if (gross1 < THREE_HUNDRED || gross2 < THREE_HUNDRED || gross3 < THREE_HUNDRED || gross4 < THREE_HUNDRED || gross5 < THREE_HUNDRED){

What are you trying to do here:

if (gross1, gross2, gross3, gross4, gross5 < THREE_HUNDRED)

and here

taxamount = gross1*taxdeduct, taxamount = gross2*taxdeduct, taxamount = gross3*taxdeduct, taxamount = gross4*taxdeduct, taxamount = gross5*taxdeduct;

I'm surprised that you are able to compile this code, but even if it does compile, these statements certainly will not give you the results you want.

The if statement control expression has to be a valid logical expression -- generally of the form:
LHS OP RHS
where LHS and RHS valid expressions and OP is a logical operator.

It can also be a simpler expression
(EXP)
where EXP can be evaluated as true or false,
or you can build up compound expressions such as:
(LHS OP RHS) OP (LHS OP RHS)
and so on, where each of the smaller expressions evaluate to true or false, and then the combined expression evaluates to true or false, but not anything like
LHS1, LHS2, LHS3 OP RHS
"gross1, gross2, gross3" is not an expression. It is 3 separate expressions so there is no way to give a single true or false value to them.

Regarding your "taxamount = gross1*taxdeduct, taxamount = gross2*taxdeduct ..." : you are trying to assign 5 different values to a single variable in a single statement? Not only is it not valid syntax, it makes no sense. What are you trying to accomplish there?

Dont worry I got it fixed

If gross1 < 300
else if gross1 >= 300 && gross1 <400
else

I did that for each gross and it came out fine, i had to do them separately, yall guys fail at helping on here, I thought I would get good help but the only was demongirl you had to be a smartass thanks anyway

yall guys fail at helping on here, I thought I would get good help but the only was demongirl you had to be a smartass thanks anyway

Are you responding to this thread? You got two good, clear responses (none of which were from demongirl). If you're not going to read the replies, and learn from them, you probably won't get any help in the future.

This article has been dead for over six months. Start a new discussion instead.