[nfbcs] Failing If Statement

Lanie Molinar laniemolinar91 at gmail.com
Fri Oct 27 18:24:13 UTC 2017


Hi. I'm sending this again since I accidentally hit reply instead of 
reply all. Thanks for the help. I knew not to put a ; at the end of an 
if statement and don't remember putting one there, but I must have at 
some point, and just didn't notice. I'm using my school's Linux lab 
remotely, so I'm not sure what version of G++ it uses. I'll have to try 
that and see if it works. That's good to know. It's so easy to miss 
those little errors like extra ;'s.


On 10/27/2017 1:11 PM, Mike Gorse wrote:
> Hi Lanie,
>
> I'm guessing that these lines are what you're referring to:
>
>    if (fin.fail());
>       cout << "Error reading file \"" << fileName << "\"\n";
>
> You have a ; at the end of the if clause. You don't want a ; at the 
> end of the line; it will make the if clause do nothing, and the 
> following line will be executed unconditionally.
>
> If you pass -Wall to g++, then it will print a warning (or at least it 
> will with the version that I have installed).
>
> Hth,
> -Mike
>
> On Fri, 27 Oct 2017, Lanie Molinar via nfbcs wrote:
>
>> Hi, everyone. Thanks for your help again last night. If you don't 
>> mind, I have another question. I'm working on another assignment and 
>> have almost everything worked out, but one of my if statements is 
>> acting weird, and I can't figure out why. It's reporting an error 
>> when it shouldn't be. I've gone over my code several times, and 
>> everything seems fine to me. Can someone please take a look? The 
>> grades.txt file I attached is used by my program. Thanks.
>>
>>





More information about the NFBCS mailing list