Program wont sort, or print

So most of the components all work on this program, but the sort does not see to work and i can't find a way to fix it. Please help.

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
#include<iostream>
#include<fstream>
#include<cmath>
#include<string>
using namespace std;

const int ArrayMax=1000;
double maxval(const double x[], int n);
double minval(const double x[], int n);
double aveval(const double x[], int n);
double standev(const double x[], int n);
void selectionSort(int array,int length);

int main ()
{
    int data=0;
    int grades_amount = 0;
    double y[ArrayMax], array;              
    ifstream file;  
    ofstream outfile;
    
    outfile.open("Sorted_Grades_Spring2012.txt");
    outfile<<selectionSort(array,data)<<endl;
    outfile.close();
    
    file.open("Grades_Spring2012.txt");
    
    if(file.fail())
    {
                   cerr<<"Error opening input file."<<endl;
                   system("pause");
                   exit(0);
    }
    
    file>>array;
    
    while ((data<ArrayMax) && !file.eof())
    {
          y[data]=array;
          ++data;
          file>>array;
          cout<<array<<endl;
          ++grades_amount;
    }
    
    cout<<endl;
    
    cout<<"The total number of grades is "<<grades_amount<<endl<<endl;
    cout<<"The Maximum score is "<<maxval(y, data)<<endl<<endl;
    cout<<"The Minimum score is "<<minval(y, data)<<endl<<endl;
    cout<<"The Average score is "<<aveval(y, data)<<endl<<endl;
    cout<<"The Standard deviation is "<<standev(y, data)<<endl<<endl;
    
    file.close();
    
    system("pause");
    return 0;
}

double maxval(const double x[], int n)
{
       double maxVal, k;
       maxVal=x[0];
       
       for (int k=1; k<n; ++k)
       {
           if (x[k]>maxVal)
           maxVal=x[k];
       }
       
       return maxVal;
}

double minval(const double x[], int n)
{
       double min;
       min=x[0];
       for (int k=1; k<=n-1; ++k)
       {
           if (x[k]<min)
           min=x[k];
       }
       return min;
}

double aveval(const double x[], int n)
{
       double sum(0);
       
       for (int k=0; k<n; ++k)
       {
           sum += x[k];
       }
       
       return sum/n;
}

double variance(const double x[], int n)
{
       double sum(0), mu;
       mu=aveval(x,n);
       
       for (int k=0; k<n; ++k)
       {
           sum += (x[k]-mu)*(x[k]-mu);
       }
       
       return sum/(n-1);
}

double standev(const double x[], int n)
{
    return sqrt(variance(x,n));
}

void selectionSort(int *array,int length)
{
	int i,j,min,minat;
	for(i=0;i<(length-1);i++)
	{
		minat=i;
		min=array[i];

      for(j=i+1;j<(length);j++)
	  {
		  if(min>array[j])  
		  {
			  minat=j; 
			  min=array[j];
		  }
	  }
	  int temp=array[i] ;
	  array[i]=array[minat]; 
	  array[minat]=temp;
		
	}

	for(int i=0;i<10;i++)
    cout<<array[i]<<endl;

}
xxx.cpp:23:38: error: no match for ‘operator<<’ in ‘outfile << selectionSort((int)array, data)’
void selectionSort(int array,int length);

outfile << selectionSort(array,data) << endl;

void selectionSort(int *array, int length)


xxx.cpp:59:23: warning: unused variable ‘k’ [-Wunused-variable]
double maxVal, k;

for (int k=1; k<n; ++k)
Last edited on
Topic archived. No new replies allowed.