Help Please! File read to and from issues and other stuff

Please Help!!!
I am fairly certain my read to and from the file is wrong and because of that I have no doubt my averaging is wrong... however I'm pretty new to this and the stuff I know is coded right is everything leading up to closing the outfile. I don't really get the file reads, even though I have read a bunch of stuff via my book, the internet, and other viable sources I just am having a hard time.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
  //


#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;



int main(int argc, const char * argv[]) {
    
    ofstream outfile;
    ifstream infile;
    double studentid, quiz, score, total, classtotal, classav, QAVG, stucount1, stucount2;
    int selection;
    
    cout<<"enter 1 to enter student data or 0 for no students. ";
    cin>> selection;
    
    outfile.open("info.txt");//opens out
    
    while (selection != 0) {
        cout << "Please enter student id: ";
        cin >> studentid;
        outfile << studentid << " ";
        
        for (quiz = 1; quiz <= 4 ; quiz++) {
            cout<<"please enter quiz grade " << quiz<<": ";
            cin>> score;
            if (score <=100 && score >=0) {
                outfile << score <<" " ;
            } else {
                cout<< "Please try again";
                break;
            }
            outfile << score <<" " ;
            stucount1++;
        }
        outfile << "\n";
        cout<<"\n";
        cout<<"enter 1 to enter student data or 0 for no students. ";
        cin>> selection;
        cout<<"\n";
    }
    outfile.close();
    infile.open("info.txt");
    
    while (stucount2 <= stucount1) {
        for (quiz = 1; quiz <= 4 ; quiz++) {
            infile >> score;
            total += score;
            
        }
        QAVG = total / 4;
        infile >> studentid;
        cout << "The average for student " << studentid << " is " << QAVG << endl;
        stucount2++;
        classtotal += QAVG;
        
    }
    classav = classtotal / stucount2;
    infile.close();
   
    
    
    return 0;
}
The way to know if it's reading the file right and figure out the average problem is to insert a cout statement after you read the data and do the math.

something like this
1
2
3
4
            infile >> score;
cout << "Test1:" << score;
            total += score;
cout << "Test2:" << total;
Topic archived. No new replies allowed.