I'm trying to make a code that takes tow words from user and store them as arrays and check if the first word's all characters are already exists in the second word , if Yes then just output Yes , if NO then output a NO . Example :
input :
ENTER THE FIRST WORD :
fos
ENTER THE SECOND WORD :
stackoverflow
output :
YES
my code is not even close to what i actually want , but i will put it down maybe it will explain what I`m trying to do .
#include <iostream>
#include <string>
using namespace std;
int main() {
char N1[7];
char N2[10];
cout << ("ENTER THE FIRST WORD : ") ;
cin >> N1;
cout <<("ENTER THE SECOND WORD : ");
cin >> N2;
for (int i = 0; i <4; i++)
{
for (int j = 0; j < 7; j++)
{
if (N1[i] = N2[j])
{
cout << ("YES") << endl;
}
else
{
cout << ("NO") << endl;
}
}
}
return 0;
}
Thanks in advance .
unordered_map<string,int>
. Also, avoidusing namespace std;
.N1[i] = N2[j]
is an assignment, not a comparison. Also, C++ hasstd::string
, no need for awkward char arrays. Also,std::string
hasstd::string::find
, which makes your task easier. Also you should really separate processes you can name into a function, in this case something likebool contains_letters(const string& a, const string& b);
.