- #1
testme
- 68
- 0
Homework Statement
Create a function called isEqual(). isEqual() takes two strings and determines if the strings are identical. isEqual (s1, s2) should be the same as s1 = = s2
Code:
#include "stdafx.h"
#include <iostream>
using namespace std;
bool isEqual(int *s, int *st, int x);
int _tmain(int argc, _TCHAR* argv[])
{
int string1[5] = {1, 2, 3, 4, 5};
int string2[5] = {1, 2, 3, 4, 5};
for(int i = 0; i < 5; i++)
{
cout << string1[i];
}
cout << endl;
for(int h = 0; h < 5; h++)
{
cout << string2[h];
}
cout << endl;
isEqual(string1, string2, 5);
if(isEqual)
{
cout << "The two strings are not the same." << endl;
}
else
{
cout << "The two strings are the same." << endl;
}
system("pause");
return 0;
}
bool isEqual(int *s, int *st, int x)
{
bool same = true;
for(int i = 0; i < x; i++)
{
same = true;
if(s == st)
{
same = true;
}
else
{
same = false;
break;
}
s++;
st++;
}
if(same == true)
{
return true;
}
else
{
return false;
}
}
What I want it to do is paste the two strings then it goes to the function compares then, returns true or false and pastes whether they are the same or not. Howver it's not reading any of them the same. Anyone know where I'm going wrong?