calculate mean from file

im having trouble calculating mean but i can't get access to the array 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
 #include<iostream>
  #include<fstream>
  #include<cstdlib>
  #include<string>
#include<iomanip>
  
  using namespace std;

  double mean_array(int[], int);
  
  int main()
  {
	

	//Now begin reading values from the file.
	ifstream inFile;

	string filename;
	
	cout << "Which file would you like to open? Include the file's name and extension: "
		 << endl;
	cin >> filename;
	
	inFile.open(filename.c_str()); //attempt to open file for input
	
	if(!inFile.fail()) //if it doesn't fail, the file exists 
	{
		cout << "A file by the name " << filename << " exists."
			 << endl;
		
	}
	
	int value;
	int array[5][2];
	int k=0;
	int i=0;
	int SIZE=5;
	
	
	while(inFile.good()) //continue until the end of the file
	{
	  
	inFile >> value;
	    
	    for( i=0; i<5; i++)
	    {
	      cout<<endl;
		  for( k=0; k<2; k++)
		  {   
		      array[i][k]=value;
		      
		      
		      cout<<setw(4)<<array[i][k];
		      
		     inFile >> value;
		    }
		    
		    
	    }
	    cout<<endl;
	    
	    
		cout<<"the mean for snowfall is "<< mean_array(array[0][0], SIZE);
	}
	
		
		
		
		
	
		
		inFile.close(); //closes the file
	
	
	
	
	return 0;
  }
  
  
double mean_array(int A[], int SIZE)
{
int total=0;
double mean;


  
 for (int i = 1; i < 13; i++)
 {
  
      //cout<<i<<endl;
      total = total + A[i];
 } 
 
    mean= (double) total / (double) SIZE;	
    return mean;
}

  
  
  
  
  
ask a specific question
Furthermore, this looks like continuation of http://www.cplusplus.com/forum/beginner/159390/
... and you apparently have not followed the advice you got there.


On line 63 you do call the function mean_array. What is the type of the first parameter that you do pass to the function?

Who is the '13' on line 88?
Topic archived. No new replies allowed.