C++ homework help

  • Comp Sci
  • Thread starter giritrobbins
  • Start date
  • #1

Homework Statement


Well I have to read in data from a text file test some conditions on certain columns and count up the failures. I am having a problem with the infile command, I have tried using infile.close(); but it does not seem to reset it.

while(infile>>y)
{
for(i;i<=(j/4);i++)
{
total=total+1;
if((2+4*i==total) && ((150>y) || (y>170)))
temp=temp+1;

if((3+4*i==total) && ((60>y)||(y>70)))
pressure=pressure+1;

if((4+4*1==total)&&((2>y)||(y>2.5)))
dwell=dwell+1;
}}

Homework Equations


n/a

The Attempt at a Solution



I have attemped infile.close(); but it did not seem to reset the counter saying it was the end of the file.

I also tried change the value of while(infile>>y) it was >>x before. Also I have tried reopening the file before this loop but it also does not seem to work.

Just to preface this there is a second loop before this that counts the total number of elements a number that I need and cannot nest within this loop.

Homework Statement





Homework Equations





The Attempt at a Solution

 

Answers and Replies

  • #2
141
0
infile.clear();
 
  • #3
infile.clear(); does not seem to work, is there a library that I need to include to use it. Right now I am using cstdlib, iostream, and fstream.
 

Related Threads on C++ homework help

Replies
4
Views
6K
  • Last Post
Replies
1
Views
3K
  • Last Post
Replies
0
Views
2K
  • Last Post
Replies
4
Views
3K
  • Last Post
Replies
0
Views
3K
  • Last Post
Replies
5
Views
1K
  • Last Post
Replies
3
Views
2K
Replies
3
Views
560
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
1
Views
1K
Top