If statement problems

Hello, I keep getting the wrong output. Is this correct?

inFile.open("pa4.sales");

if (sales < A) // Bob
{
commission = ZERO;
inFile >> name >> sales;
cout << setw(12) << name << setw(9) << sales << setw(10)
<< commission << setw(15) << (sales * commission);
cout << endl;
}

else if (sales >=A && sales < B)
{
commission = FIVE;
comm = FIV;
inFile >> name >> sales;
cout << setw(12) << name << setw(9) << sales << setw(10)
<< comm << setw(15) << (sales * commission);
cout << endl;
}

else if (sales >= B && sales < C)
{
commission = SEVEN;
comm = SEV;
inFile >> name >> sales;
cout << setw(12) << name << setw(9) << sales << setw(10)
<< comm << setw(15) << (sales * commission);
cout << endl;
}

else if (sales >= C )
{
commission = TEN;
comm = TE;
inFile >> name >> sales;
cout << setw(12) << name << setw(9) << sales << setw(10)
<< comm << setw(15) << (sales * commission);
cout << endl;
}
I ran into the same problems when inputting values, however that was with binary mode on. It should be pretty easy to debug this code as it is writing as text, you can check the output with each section of the code.

Also are you trying to empty the text file and write this data, append to end of file, etc?

And have you gone inFile.close() to write the data from buffer into file.\

--

I do see some errors in your logic, they may not cause bugs, but they are redundant pieces of code, etc:
if (sales < A) // Bob
{

}
else if (sales >=A && sales < B) //A would have to already be == or >= A
{

}
Last edited on
1. Can you please post the entire code?

2. What is the output that you get and what output is it supposed to produce?

3. Can you you tags please?
Topic archived. No new replies allowed.