Hey Guys! I have a task where it's neccassary to compare two array of strings to eachother. However when I try to test the program, it prints out a higher number than 1 for some strings. Haven't seen something like this ever, because the results could only be true or false. Any suggestions what could be the problem?
#include <iostream>
#include <string>
usingnamespace std;
int lancok;
int i;
int n;
int j;
int main()
{
//input the number of string pairs, and the strings
cin >> lancok;
string evo[30];
string evett[30];
bool help[60];
int duplalancok = lancok*lancok;
for(i=1;i<=lancok;i++){
cin >> evo[i];
cin >> evett[i];
}
//comparing the strings to eachother
for(i=1;i<=lancok;i++){
for(n=1;n<=lancok;n++){
if(evett[i]!=evo[n]){
help[n]=true;
}
}
}
//printing out the result of the comparison
for(n=1;n<=duplalancok;n++){
cout << help[n] << endl;
}
return 0;
}
example input:
4
fox rabbit
rabbit grass
bird seeds
fox bird
The first thing I would try is to initialize all the variables when you define them.
It looks like the "help" array has whatever was i that block of memory when "help" was created and the 0s and 1s are likely the only part of the array that was sctually used.