reading txt files

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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
int main()
{
double x, avg, max=0.0, min=100.0,totalsat=0.0, totalunsat=0.0, totalout=0.0;
int invalid=0, outstanding=0, satisfactory=0, unsatisfactory=0, kount=0;
 
ifstream inFile;
inFile.open("grades.txt");
inFile >>  x;
cout <<"                        Written By: Sean Dane\n\n\n";
        cout <<" Score  Score Rating \n";
        cout <<" _____  _____________\n\n\n";
while (! inFile.eof())
{
       
        if ( x >= 0 &&  x <= 100)      
                kount ++ ;
   
       
        cout <<"";
        cout << " " << x;
 
    if (x < 0 || x > 100)
        {
                
                invalid = invalid +1;
      cout << "    Invalid \n\n\n";
 
        }
        else if ( x >= 90 &&  x <= 100)
        {
                
                outstanding = outstanding +1;
                totalout = totalout + x;
                cout << "    Outstanding Score\n\n\n";
 
        }
        else if ( x >= 60 &&  x <= 89)
        {
                
                satisfactory=satisfactory + 1;
                totalsat = totalsat + x;
                cout << "    Satisfactory Score\n\n\n";  
 
        }
        else if ( x >= 0 &&  x <= 59)      
        {
                
                unsatisfactory=unsatisfactory+1;
                totalunsat = totalunsat + x;
                cout << "    Unsatisfactory Score\n\n\n";
        }
    else
        cout << setw(10) <<  x << endl;
        inFile >> x;  
}  
 
        cout <<"\n\n\n__________________________________________\n\n\n";
        cout << "\n\n\n Number of outstanding scores            " << outstanding;
        cout << "\n\n\n Number of Satisfactory scores           " << satisfactory;
        cout << "\n\n\n Number of Unsatisfactory scores " << unsatisfactory;
        cout <<"\n\n\n";
 
        cout<< setprecision(4);
        avg=(totalout+totalsat+totalunsat)/(outstanding+satisfactory+unsatisfactory);
        cout << " Average of the combined scores                "<<avg;
        cout <<"\n\n\n";
 
       
        if (x>=max && x<=min)
        if (x > min)
        min = x;
         if (x < max)
        max = x;
       
        cout<< " The high score is                   "<<max<<"\n\n\n";
        cout<< " The low score is                    "<<min<<"\n\n\n";
       
 
        inFile.close();  
 
        cout << "\n\n\n Hit enter to continue...";  
        cin.get();  
        return 0;
}



when the program tries to open the text file it just scrolls "0 unsatisfactory score" forever.

the text file has grades in it I'm trying to sort

63
75
121
72
72
78
67
-9
80
63
75
90
89
43
59
93
82
-113
33
97
202
40
60
55
88
91
101
66
Last edited on
My guess is that your program can't see "grades.txt". Try entering the fully qualified path to that file and see where that gets you, remember to double up on your back slashes or use the forward slash instead.
Topic archived. No new replies allowed.