Determine if relations are reflexive

Hello all, I am working on a program that will look at a relation and determine if it is reflexive. So far I am able to go through the pairs and determine if they are equal. I cannot figure out a way for the program to determine if the relation is reflexive. I would assume if for a number it does not find a pair then the function should return false. I cannot figure out how to code for this. Any tips would be greatly appreciated. ar1 is the first numbers in each pair and ar2 is the seconds numbers. The relation I am testing now is reflexive, but it return false for some reason.

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
37
38
39
40
41
42
43
#include <iostream>
using namespace std;
bool isreflexive(int ar[],int n,int ar2[],int nn)
{
int j,i = 0;
bool hold = true;
cout<<"n " <<n<<endl;
for(i = 0; i <n; i++)
   {
    cout<<"i "<<i<<endl;
    if(ar[i] == ar2[j])
    {
      cout<<"match"<<endl;
     j++;
    }
   else
     {
       cout<<"not a match"<<endl;
       j++;

     }
}


}


int main()
{

int  ar[] = {1,2,3,4,4,7,7 };
int ar2[] = {1,2,3,4,7,4,7};
int n = sizeof(ar)/sizeof(int);
int nn = sizeof(ar2)/sizeof(int);
//cout<<n<<endl;


bool reflexive = isreflexive(ar,n,ar2,nn);

cout<< reflexive <<endl;

}
I think it returns false because you did not specify any return statement at all. So function returns some mysterious value.
That is what I' m having trouble figuring out where to put the return false if the relation is not reflexive and true if it is.
Topic archived. No new replies allowed.