I'm new to C++ and I'm trying to compare two unsorted vectors elements against each other and determining if they match or not.
for example: 1 4 9 16 9 7 4 9 11 and 11 11 7 9 16 4 1 these would be considered a match.
I've tried using firstVector == secondVector, but that does not work when they vectors are not sorted, I'm specifically trying to compared them while they are unsorted but am struggling.
int main() {
int incorrectMatches = 0;
int totalMatches = 0;
int input = 0;
vector <int> firstVector;
vector <int> secondVector;
do {
cout << "Please enter a number for first vector: ";
cin >> input;
firstVector.push_back(input);
cout << endl;
}
while (input > 0);
input = 0;
firstVector.pop_back();
do {
cout << "Please enter a number for second vector: ";
cin >> input;
secondVector.push_back(input);
cout << endl;
}
while (input > 0);
secondVector.pop_back();
for (int loop = 0; loop < firstVector.size(); loop++) {
cout << firstVector[loop] << " ";
}
cout << endl;
for (int loop = 0; loop < secondVector.size(); loop++) {
cout << secondVector[loop] << " ";
}
cout << endl;
int vectorSize = firstVector.size();
for (int i = 0; i < vectorSize; i++) {
if (firstVector[i] == secondVector[i]) {
totalMatches = totalMatches++;
}
else {
incorrectMatches = incorrectMatches++;
}
}
cout << "There were " << totalMatches << " matches." << endl;
cout << "There were " << incorrectMatches << " incorrect matches";
/*
if (firstVector == secondVector) {
cout << "Your vectors match!";
}
else{
cout << "Your vectors don't match!";
}
*/
/*
for (int i = 0; i < input; i++) {
cout << "Please enter a number (1-9): ";
myVector.push_back(input);
cout << endl;
myVector[i] = i;
cout << "Vector entry: " << myVector[i] << endl;
}
*/
system("pause");
return 0;}