Passing arrays

When i call maxFunc and pass the array from the file it wont let me pass in the values. Why?
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
/*
Let A be an array of n elements. Write a template function, maxfunc(…),  which takes an unsorted array of type <class T> as an input parameter and returns the element with the maximum value. Assume the operators <  and > are defined for the class T. In this question, you may hardcode n=5. You must write all functions you call, and also needs to write a main() to test the following data arrays stored in a data file (data.txt):
 
 4 1 13 3 2
 1.1 4.1  8.1  5.2  2.3
 the student is in class                 //  > is judged on the basis of alphabetical order
 
 In addition, the results should be printed out in main( ) routine.
*/

#include <iostream>
#include <fstream>

using namespace std;

const int n =5;
int A[n];

template <class T>

T maxfunc()
{
    int max=0;
    for(int i=0; i< 6; i++)
    {
        if(A[i]>max)
            A[i] = max;
    }
    cout << "The max value is " << max << endl;
    return 0;
};


int main()
{
    ifstream ins;
    ins.open("data.rtf");
    cin.getline("data.rtf", 5);
    if(ins.is_open()){
        cout << "File is open";
    }
    else{
        cout << "File NOT Open";
    }
    while(ins.good())
    {
        for(int i=0; i<6; i++)
            cout << A[i] << " " << endl;
    }
    maxfunc(A);
    
    system("pause");
    return 0;
}

First A[] is decraled as global, so you don't need to pass any parameters
Then maxfunc don't have/need any parameter but you pass A as parameter in main
Last use ins>>A[i]; to fill the array with value from file
I dont understand, how can i rewrite it.
Topic archived. No new replies allowed.