bool function return

hey guys, I am trying to write a function which compares 2 arrays of characters. At the end it only return true. Please help.
Here is the whole code;

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
44
45
46
#include <iostream>
using namespace std;

bool equal(char a[],int index_a, char b[], int index_b)
{
  if(index_a!=index_b)
   { return false; }
     else 
    {
      for(int i=0;i<index_a;i++)
         if(a[i]!=b[i])
        return false;
     else 
       return true;
    }
} 
  
int main()
{

char myname[30];
cin>>myname;
int index_1=0;
 while(myname[index_1]!='\0')
    { myname[index_1+1];
      index_1++;
    }

char yourname[30];
cin>>yourname;
int index_2=0;
 while(yourname[index_2]!='\0')
    { yourname[index_2+1];
      index_2++;
    }

equal(myname,index_1,yourname,index_2);

if(true)
  cout<<"The arrays are identical"<<endl;
else 
 cout<<"The arrays are NOT identical"<<endl;

cout<<index_1<<endl;
cout<<index_2<<endl;
}
Never mind, I figured it out.
Thanks
Glad you figured it out! Looks to me like you included your else statement inside your for loop, but didn't actually want it there? If you feel like it, giving closure to the topic for future generations would be great. Feel free to post a response to your own question!
Topic archived. No new replies allowed.