Help on array

I am trying to write a program that ask the user for a string and tell them yes or no, whether their string is a letter in the Greek alphabet. I am stuck on when the input is not a Greek letter. If I add an else statement the program only tells it is a Greek letter when the input is Alpha. Can anyone tell me how to solve this and explains to me that why it doesn't work with else statement? Thank you!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<string>
#include<iostream>
using namespace std;
int main(){

	string letters[24]={"Alpha","Beta","Gamma","Delta","Epsilon","Zeta","Eta","Theta","Iota",
		"Kappa","Lambda","Mu","Nu","Xi","Omicron","Pi","Rho","Sigma","Tau","Upsilon","Phi","Chi","Psi","Omega"};
	string input;
	while (input != "exit") {
        cout << "Please enter string :";
        cin >> input;
		for (int i=0; i<=23;i++) {
            if (letters[i] == input) {
				cout<<"Yes,you entered a greek letter!"<<endl;
				break;}}}
		
return 0;
}
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<string>
#include<iostream>

using namespace std;

int main(){
   string letters[24] = { Alpha", "Beta", "Gamma", "Delta", "Epsilon", "Zeta", "Eta", "Theta", "Iota", "Kappa", "Lambda", "Mu", "Nu", "Xi", "Omicron", "Pi", "Rho", "Sigma", "Tau", "Upsilon", "Phi", "Chi", "Psi", "Omega" };
		
   string input;
   bool found = false;

   while ( input != "exit" )
   {
      cout << "Please enter string :";
      cin >> input;
      found = false;

      for ( int i = 0; i <= 23; i++)
      {
         if (letters[i] == input)
        {
            found = true;
            break;
         }
      }
		
      if ( found == true )
         cout<<"Yes, you entered a greek letter!"<<endl;
      else
         cout<<"No, you did not enter a greek letter!" << endl;
  }
   return 0;
} 
Last edited on
Topic archived. No new replies allowed.