Hello again, I'm having a problem with my program. It's supposed to read from a file the lengths of a triangles sides and output what kind of triangle it is. The problem im getting is that its outputting some gibberish before it gets to the actual values. Here is what its outputting:
2821744 2821848 1999546570
Not a triangle.
3 6 9
Scalene
4 4 4
Equalateral
1 1 9
Not a triangle.
EqualateralPress any key to continue . . .
Duh. Thanks. That cleared up the top lines. But it still seems to be reading after what i thought would be eof.
Now im getting:
works
.
.
1 1 9
Not a triangle. <--- last working line
Equalateral. <---- all lines after this line shouldnt be here
1 1 9
Not a triangle.
Equalateral.Press any key to continue. . .
Got it. I put line 40 back and included a priming read on line 13 and seems to work okay. But i think i'm getting the eof issue ive read about here. Whats the way around eof?
When reading from a file (or other streams) is often useful breaking a loop in the middle of its block, not at the beginning or at the end.
You can check if the stream is good adding this after you read the input:
1 2
if ( !infile.good() ) // something went wrong during input | you reached the end of the stream
break; // exit from while