I've fallen and I can't get up. I don't want my homework done for me, but this particular piece of my solution to a homework problem is killing me. I need some other eyes to help me see the light on what I'm missing here.
A class named myClass has private data consisting of several sorted int arrays, IE
Code:
int arrayOne[10]={1,3,5,7,9,11,13,15,17,19};
int arrayTwo[10]={2,4,6,8,10,12,14,16,18,20};
That class has a public member that will generate a pseudo-'random' number when it is called, and then check to see if that number is in the 'odd' array, like this :
Code:
bool myClass::tryOdd()
{
int random = rand()%20;
bool response;
int arrayLength = 10; // number of elements in the odd array
if ( arraySearch( odd, arrayLength, random ) )
{
response=true;
}
else
{
response=false;
}
return(response);
}
The myClass::arraySearch() member is implementedlike this:
Code:
bool myClass:arraySearch( int name[], int length, int match )
{
bool response;
int start = 0;
int index;
int* result = find( name+start, name+length, match );
if ( result == name+length )
{
response = false;
}
else
{
response = true;
}
return(response);
}
My problem here with this design is that no matter what I do, I keep getting incorrect response. I even removed the rand() call and set random = 5, which is obviously in arrayOne as an odd number, but the client still receives a bool false return. What's more annoying is that when I take the arraySearch algorithm and just create a little stub program with it, and a single array so I'm isolating it, it works fine:
Code:
#include<iostream>
#include<algorithm>
using namespace std;
const int name[]={1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35};
int main()
{
bool response;
int match = 5;
int start = 0;
int length = 18;
int index;
int* result = find( name+start, name+length, match );
if ( result == name+length )
{
cout << "False" << endl;
}
else
{
cout << "Match " << *result << endl;
}
return(0);
}
Is this a scope problem, or? What am I missing here that I can't even FORCE an odd number into 'random' and get a 'true' response back at the client?