Need help to fix my function! (its supposed to check if two words are the same

I dont know what is wrong with my code. Can anybody help?

#include <iostream>

using namespace std;
bool isEqual(char word1[100], char word2[100])
{
bool check = true;
for (int i=0;i<100;i++) // loops through every letter of the name
{
if (word1[i] == '\0'&& word2[i]== '\0') // eliminates the answer from being true if only some of the name is written
{
check= true;
break;
}

if (toupper(word1[i]) != word2[i]) // checks through every letter
{
check= false;
break;

}


}
if (check == true)
{
return true;
}

else
{
return false;
}

}

int main()
{
char firstword[100];
char secondword[100];

cout<< "Give me two words and I will tell you if they are the same! cause I'm a magician!!!";
cout<< "What is your first word?";
cin>> firstword;
cout<< "What is your second word?";
cin>> secondword;
if (isEqual(firstword,secondword)== false)
{
cout << "ABRACADABRA! The words are not the same!";
}
else
{
cout << "ABRACADABRA! The words are the same!!!";
}





return 0;
}
Please use the code format tag to format your code in future.

I had to format it myself so I could see the code, so I've reposted it:
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
47
48
49
50
51
52
#include <iostream>

using namespace std;

bool isEqual(char word1[100], char word2[100])
{
	bool check = true;
	for (int i=0;i<100;i++) // loops through every letter of the name
	{
		if (word1[i] == '\0'&& word2[i]== '\0') // eliminates the answer from being true if only some of the name is written
		{
			check= true;
			break;
		}

		if (toupper(word1[i]) != word2[i]) // checks through every letter
		{
			check= false;
			break;
		}
	}
	if (check == true)
	{
		return true;
	}
	else
	{
		return false;
	}
}

int main()
{
	char firstword[100];
	char secondword[100];

	cout<< "Give me two words and I will tell you if they are the same! cause I'm a magician!!!";
	cout<< "What is your first word?";
	cin>> firstword;
	cout<< "What is your second word?";
	cin>> secondword;
	if (isEqual(firstword,secondword)== false)
	{
		cout << "ABRACADABRA! The words are not the same!";
	}
	else
	{
		cout << "ABRACADABRA! The words are the same!!!";
	}

	return 0;
}


Why are you calling toupper on word1[i], and not toupper on word2[i]? I take it you're attempting an case insensitive comparison, otherwise you shouldn't use toupper at all.
Exactly what KBW said.

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

bool isEqual(char word1[100], char word2[100])
{
	bool check = true;
	for (int i=0;i<100;i++) // loops through every letter of the name
	{
		if (word1[i] == '\0'&& word2[i]== '\0') // eliminates the answer from being true if only some of the name is written
		{
			check= true;
			break;
		}

cout << word1[i] << " " << word2[i] << endl; // for human checking

		if (word1[i] != word2[i])// checks through every letter
		{
			check= false;
			break;
		}

	}
	if (check == true)
	{
		return true;
	}
	else
	{
		return false;
	}
}
Topic archived. No new replies allowed.