Averaging arrays

I am trying to average the negative numbers and positive number and of course the total average. This is what I have so far. I'm sorry, I am a beginner.
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

//This will read in a list of n values, where n is not known ahead of time. The number of values read into the array will be saved in n.
vector<int> readList()
{
    std::vector<int> result;
    
    ifstream inFile;
    
    inFile.open("setA.txt");
    
    for (int x; inFile >> x; )
    {
        result.push_back(x);
    }
    
    return result;
}

//array is a one-dimensional array of integers and n is the number of elements in that array that contain valid data values. Both of these are input parameters to the function. The function must calculate 1) the average of the n integers in array, storing the result in ave; 2) the average of the positive numbers (> 0), storing the result in avePos, and 3) the average of the negative numbers (< 0), storing the result in aveNeg.

void avgs (std::vector<int> &array, int &ave, int &avePos, int &aveNeg)
{
    int sum = 0, pos_sum = 0, neg_sum = 0, pos_count = 0, neg_count = 0;
    for (auto i : array)
    {
        sum += i;
        if (i > 0) { pos_sum += i; ++pos_count; }
        {
            count_if(<#_InputIterator __first#>, <#_InputIterator __last#>, <#_Predicate __pred#>)
        }
        if (i < 0) { neg_sum += i; ++neg_count; }
    }
    
    if(pos_sum) avePos = pos_sum / pos_count;
    if(neg_sum) aveNeg = neg_sum / neg_count;
}
do you know what 'average' means?

line 29 makes no sense.

On line 34/35 you're using the wrong expression for if. Try to figure out what the right expression could be (hint: math)
Topic archived. No new replies allowed.