Help with finding number of elements

Jan 30, 2013 at 6:55am
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??
Jan 30, 2013 at 7:13am
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.