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!!!";
}
#include <iostream>
usingnamespace 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)
{
returntrue;
}
else
{
returnfalse;
}
}
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.
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)
{
returntrue;
}
else
{
returnfalse;
}
}