please help with array

I need help adding a value returning function that uses a do loop so it can determine the number of elements in the array that are between 110 and 155. how can I add that to this program! Help!


#include <iostream>
#include <ctime>
using namespace std;

//function prototypes
void displayArray(int numbers[], int numElements);
int getRandom(int numbers[], int numElements);

int main()
{
//declare array
int randNums[100] = {0};


//initialize random number generator
srand(static_cast<int>(time(0)));
//assign random integers from 100
//through 200 to the array
for (int sub = 0; sub < 100; sub += 1)
randNums[sub] = 100 + rand() % (200 - 1 + 1);
//end for

//display array
displayArray(randNums, 100);

system("pause");
return 0;
} //end of main function

//*****funtion prototype*****
void displayArray(int numbers[], int numElements)
{
for (int sub = 0; sub < numElements; sub +=1)
cout << numbers[sub] << endl;
//end for
} //end of displayArray function

int getRandom(int numbers[], int numElements)
{
//assign first element's value
//to the high variable
int random = numbers[0];

//begin the search with the second element
int x = 1;
//search for random number
while (x < numElements)
{
if (numbers[x] > random)
random = numbers[x];
//end if
x +=1;
} //end while

return random;
} //end of getRandom function
just add this prototype:
 
int ValuesInRange(int [],int,int,int);

before other functions, then implement it
1
2
3
4
5
6
7
8
9
10
int ValuesInRange(int a[],int len,int min,int max){
    if(len<=0)return 0;
    if(min>max)swap(min,max);
    int range=0;
    do{
        --len;
        if(a[len]>=min && a[len]<=max) ++range;
    }while(len>0);
    return range;
}


Topic archived. No new replies allowed.