[nfbcs] Failing If Statement

Mike Gorse mike at straddlethebox.org
Fri Oct 27 19:46:01 UTC 2017


Hi Lanie,

On Fri, 27 Oct 2017, Lanie Molinar wrote:

> Hi. I was getting two error messages during one of the tests my school's 
> testbed program ran, so I tried to fix it, and I'm now getting some results I 
> never expected. Is my redesigned if statement toward the bottom of the 
> readFile function not right?

You have:
    if ((numGrades != 10) && (fin.fail() == false))

One way to debug this would be to add a cout() into the if clause and the 
else clause that would print out the values of numGrades and fin.fail().

Anyhow, fail() starts to return true once the end of the file has been 
reached, and your while loop continues until it no longer succeeds, at 
which point fin.fail() starts to return true. So the block in your if 
clause never executes, since it checks that fin.fail() returns false, 
which it never does.

-mike




More information about the NFBCS mailing list