Answer the question
In order to leave comments, you need to log in
How to check if a letter is in an array?
Can someone tell me how to check that a certain character is contained in an array of characters?
My problem now is that my method does not work correctly. I can’t figure out how to make it look specifically for the first letter in the entire array, then the second, and so on until the end.
#include <iostream>
using namespace std;
std::string letters[26] = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j','k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't','u','v','w','x', 'y', 'z'];
string myString = "hello";
void Encode(){
letters.for(i = 0;i<letters.length;i++){
if(myString[i] == letters[i])
}
}
int main()
{
cout<<"Hello World";
return 0;
}
Answer the question
In order to leave comments, you need to log in
if(myString[i] == letters[i])
what? in your loop, letters are compared at equal positions of the search string and an array of letters, i.e. first the first letter hello with the first letter of the array, then the second letter hello with the second letter of the array, and so on.
you have to debug your code in order to understand where the problem is, you would see it immediately
here you need a double loop, separately for the letters hello and separately for the array of letters
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question