#include <iostream>
#include <string>
usingnamespace std;
int main(){
int primary = 0;
string strings[3];
cout << "Enter the first string.\n";
cin >> strings[0];
cout << "Enter the second string.\n";
cin >> strings[2];
while(primary != 1){
cout << "Enter the new first string.\n";
cin >> strings[1];
if(strings[1] == strings[0]){
cout << "The old and the new string match.\n";
}
else{
cout << "The first string has been changed.\n";
strings[0] = strings[1];
}
cout << "Enter the new second string.\n";
cin >> strings[3];
if(strings[3] == strings[2]){ // CONFUSION
cout << "The old and the new string match.\n";
}
else{
cout << "The second string has been changed.\n";
strings[2] = strings[3];
}
}
}
I changed the strings from an array to multiple independent strings, string1, string2, string3 and string 4, and now it works flawlessly. It's impossible to use arrays with strings, isn't it?
It's simple, there is no strings[3]. When indexing arrays, we start from 0. So an array with 3 elements has elements 0, 1 and 2. If you want to use strings[3] you need to declare strings with 4 elements.