[nfbcs] Failing If Statement

Lanie Molinar laniemolinar91 at gmail.com
Fri Oct 27 19:50:06 UTC 2017


Okay, then if that doesn't work,I need to find a way to get rid of the 
duplicate error messages in test 5:

Starting Test 1

Here we will read the file that has the following text:
    90 86 95 76 92 83 88 87 91 100
The sum is 888 so the average is 88.8%. You will need to round
correctly using the cout.precision() statement

    > Please enter the filename: /home/cs124/assignments/assign26a.txt
    > Average Grade: 89%

Test 1 passed.
------------------------------------------------------------

------------------------------------------------------------
Starting Test 2

this is the same as before except there is an extra newline at the
end of the file. Your program will need to not read the last number
twice. If you do, the sum will be 988 which will yield 89.8%.
Read the section in the book titled "Reading to the end of the file"
for a discussion on why this might happen and how to fix it

    > Please enter the filename: /home/cs124/assignments/assign26b.txt
    > Average Grade: 89%

Test 2 passed.
------------------------------------------------------------

------------------------------------------------------------
Starting Test 3

This should yield an error because there are 12 items in the file

    > Please enter the filename: /home/cs124/assignments/assign26c.txt
    > Error reading file "/home/cs124/assignments/assign26c.txt"

Test 3 passed.
------------------------------------------------------------

------------------------------------------------------------
Starting Test 4

This should yield an error because there are 3 items in the file

    > Please enter the filename: /home/cs124/assignments/assign26d.txt
    > Error reading file "/home/cs124/assignments/assign26d.txt"

Test 4 passed.
------------------------------------------------------------

------------------------------------------------------------
Starting Test 5

This should yield an error because the file does not exist

    > Please enter the filename: /home/cs124/assignments/assign26e.txt
    > Error reading file "/home/cs124/assignments/assign26e.txt"
    > Error reading file "/home/cs124/assignments/assign26e.txt"\n
Exp: No output

Test 5 failed.
------------------------------------------------------------


============================================================
Failed 1/5 tests.
============================================================

[living4god1991 at LinuxLab01 ~]$


On 10/27/2017 2:46 PM, Mike Gorse wrote:
> 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