Help with finding number of elements

The situation is that I have an array:
a[]: filled with 10 integers.

I need to create a function that will find and return the number of elements that are >= 80 and <= 100 in any array of any size.

I'm only in an intermediate programming class so we're using for loops, while loops, and basic things like that.

Any ideas??
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

int num_of(int array[], int size)
{
    int num = 0;
    for(int i = 0; i < size; ++i)
        if((array[i] >= 80) && (array[i] <= 100))
            ++num;
    return num;
}

int main()
{
    int a[10] = {10,0,80,20,100,30,40,90,70,50};
    std::cout <<  num_of(a, 10) << std::endl;
}

Output:
3

Topic archived. No new replies allowed.