Counter Not Working

EDIT: Nevermind. I figured it out. So, so, so ridiculous.


Okay. Here's the premise of the program.

The program must read in a student ID and 3 exam scores.

777 89 98 67
444 34 67 12
999 23 54 67

It then outputs the data in a nice neat form and displays the average score. The program also checks for invalid data a writes "Invalid data" in place of the average if one of the numbers is out of range. Now, here's the problem. My counters which keeps track of how many valid and how many invalid records there don't work. Well, my "invalid" counter works. However, my valid counter insists on saying there are over 1,074,015,075 valid records when there are usually only 5 or 6. I've tried everything I can think of but I have NO idea what's causing this. No, it's not an infinite loop. My output file would be very long if that were the case. Both counters follow the exact same path, so I have no clue why this is happening.

Here are some chunks of code to hopefully help figure this out.

Here's my Main. I cut out some unnecessary code for this example and added in extra comments.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
int main()
{
    StudType stud;
    int count = 0;

    stud.ReadData( inFile ); //Priming read

    while( inFile )
    {
        if( stud.ValidRd() )  //determines if the data is valid and returns bool
        {
            stud.IncValidity( true );//increments the validData counter (the one that doesn't work.)
            stud.FindAvg();
        }
        else
            stud.IncValidity( false );//increments the counter that does work
                        
        stud.WriteData( outFile );
        stud.ReadData( inFile );
    }

    outFile<<endl<<"Number of valid records:  "<<stud.WriteValCount()<<endl;
    outFile<<"Number of invalid records:  "<<stud.WriteInvalCount()<<endl<<endl;
}
]

Here are the functions that use the counters...

Default constructor
1
2
3
4
5
StudType::StudType()
{
    id, ex1, ex2, ex3, avg = -1;
    countVal, countInval = 0;
}


1
2
3
4
5
6
7
void StudType::IncValidity( bool validity )
{
    if( validity )
        countVal++;
    else
        countInval++;
}


1
2
3
4
int StudType::WriteValCount()
{
    return countVal;
}


I hope this is enough information to figure this out. I didn't want to post ALL the code. That'd be just messy. Any and all help is, of course, much appreciated.
Last edited on
Topic archived. No new replies allowed.