Problems getting correct numbers

I am a beginner at C++, the output is pretty self explanatory. I'm trying to make a number sorting program with other features, but the numbers are all wrong.

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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <iostream> 
#include <iomanip>
#include <fstream>

using namespace std;
 
void readData(int list[], int size);


int main()
{
    int size = 50;
	int scores[50] = {0};
	int range (0);
	int rangeA(0);
	int rangeB(0);
	int rangeC(0);
	int rangeD(0);
	int a;
    int b;
    double avg;
    int c;
    int d;
    double avgA;
    int e;
    int f;
    double avgB;
    int g;
    int h;
    double avgC;
    int i;
    int j;
    double avgD;
    int aAvg (0);
    int aAvgA(0);
    int aAvgB(0);
    int aAvgC(0);
    int aAvgD(0);
    int paa, paaA, paaB, paaC, paaD;
    
	readData(scores, size);               //  call the function to load the array
	
	sort(scores, scores + 50);
    for ( int n=0 ; n<50 ; ++n )
    {
         if(scores[n] <=599&&scores[n] >= 300)
         {
             rangeA = rangeA + 1;
             c = scores[n];
             d = scores[n] + c;
         }
         if(scores[n] <=699&&scores[n] >= 600)
         {
             rangeB = rangeB + 1;
             e = scores[n];
             f = scores[n] + e;
         }
         if(scores[n] <=799&&scores[n] >= 700)
         {
             rangeC = rangeC + 1;
             g = scores[n];
             h = scores[n] + g;
         }
         if(scores[n] <=850&&scores[n] >= 800)
         {
             rangeD = rangeD + 1;
             i = scores[n];
             j = scores[n] + i;
         }
         range = range + 1;
         a = scores[n];
         b = scores[n] + a;

                   
    }
    int highA, highB, highC, highD;
    int lowA, lowB, lowC, lowD;
         avg = b/range;
         avgA = d/rangeA;
         avgB = f/rangeA;
         avgC = h/rangeA;
         avgD = j/rangeA;
         lowA = scores[1];
         highA = scores[rangeA];
         lowB = scores[rangeA + 1];
         highB = scores[rangeB];
         lowC = scores[rangeB +1];
         highC = scores[rangeC];
         lowD = scores[rangeC + 1];
         highD = scores[rangeD];
         for ( int n=0 ; n<50 ; ++n )
         {
             if(scores[n] > avg)
             {
                 aAvg = aAvg + 1;
             }
             
             if(scores[n] > avgA && scores[n] <= 599)
             {
                  aAvgA = aAvgA + 1;
             }
             if(scores[n] > avgB && scores[n] <= 699)
             {
                  aAvgB = aAvgB + 1;
             }
             if(scores[n] > avgC && scores[n] <= 799)
             {
                  aAvgC = aAvgC + 1;
             }
             if(scores[n] > avgD && scores[n] <= 850)
             {
                  aAvgD = aAvgD + 1;
             } 
         }
         paa = (aAvg/range)*100;
         paaA = (aAvgA/rangeA)*100;
         paaB = (aAvgB/rangeB)*100;
         paaC = (aAvgC/rangeC)*100;
         paaD = (aAvgD/rangeD)*100;
         
         cout << "Score Range     No.     Average     Lowest     Highest     No. of scores above average     Percent above average" << endl;
         cout << "300-599         " << rangeA << "       " << avgA << "      " << lowA << "       " << highA << "       " << aAvgA << "                             " << paaA << "%" << endl;
         cout << "600-699         " << rangeB << "       " << avgB << "      " << lowB << "       " << highB << "       " << aAvgB << "                             " << paaB << "%" << endl;
         cout << "700-799         " << rangeC << "       " << avgC << "      " << lowC << "       " << highC << "       " << aAvgC << "                             " << paaC << "%" << endl;
         cout << "800-850         " << rangeD << "       " << avgD << "      " << lowD << "       " << highD << "       " << aAvgD << "                             " << paaD << "%" << endl;
         
         cout << "Average: " << avg << endl;
         cout << "No. of scores above average: " << aAvg << endl;
         cout << "Percent above average: " << paa << "%" << endl;
         
	system("PAUSE");
	return 0;
}

void readData(int list[], int size)      //  This function loads an array from an input file 
{
	ifstream infile;

    infile.open("Input.DAT");

	if (!infile)
	{
		cout << "Cannot open the input file. Program terminates!" 
			 << endl;
		return ;
	}
	int score;
	int index = 0;

	infile >> list[index];

	while (index < size - 1)
	{
		index = index + 1;
		infile >> list[index];
	}
		infile.close();

}



Input.DAT
1
2
3
4
376 389 450 735 600 576 612 700 450 628 778 389 667 500 475 550 687 791 829 344
549 476 400 587 535 657 789 583 340 764 422 826 566 436 565 834 533 423 837 701
847 521 746 356 582 465 493 593 425 421


I can't for the life of me figure out why the numbers are all messed up.
In line 43 it looks like you are calling a function to sort your array (assuming it was initialized properly); however, I don't see a sort function, a prototype for the function if you created it, or the line #include <algorithm> if you didn't create it. That is one major issue that needs to be addressed. Also, please give us the output of your code (again i'm assuming yours compiles), and let us know exactly which numbers are messed up. Also, keep in mind command prompt is limited to a width of 80 characters, so you output has some very bad formatting issues due to that.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Score Range     No.     Average     Lowest     Highest     No. of scores above a
verage     Percent above average
300-599         31       38      344       600       31
    100%
600-699         6       44      612       400       37
   600%
700-799         8       51      421       422       45
   500%
800-850         5       54      423       389       50
   1000%
Average: 33
No. of scores above average: 50
Percent above average: 100%
Press any key to continue . . .


That's the output.
It's supposed to come out with more realistic number values, like this:
1
2
3
4
5
6
7
8
9
            Score  Range       no.            Average         Lowest        Highest         No. of scores above average        Percent above average
             300 - 599            31             476.45             340            593                            14                                             45 %
             600 - 699             6              641.83              600            687                             3                                              50 %                           
             700 - 799             8              750.50              700            791                             4                                              50 %  
             800 - 850             5              834.60              826            847                             2                                              40 % 

                Average :  575.96    
               No. of scores above average : 24
                Percent above average  48 %

Topic archived. No new replies allowed.