Question: I have written a short program that takes a user input and then checks a string for a match to the users input but I need to add another function that checks make sure that the user input is in the string and if its not to return an error.

Here is my code for reference:

```
const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.,’ ";
int main()
{
    char letter; //Variable holding user entered letter 
    cout << "Please enter letter in the aplhabet:" << endl;
    cin >> letter;
    cout << "The Position of " << letter << " in the string is: " << ALPHABET.find(letter) << endl;

    return 0;
}

```

I think I ought to add an if/else statement that first checks to see if the input is correct and if it is output the position in the string and if not return and error.

Answer: 
If you wanted to be fancy, you could write your own function. However, `string::find()` is ok. All you need to check is whether or not the returned index is valid or not.

```
// Example program
#include <iostream>
#include <string>

using namespace std;

const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.,’ ";
int main()
{
    char letter; //Variable holding user entered letter 
    string::size_type index; //Index where char is found in string
    cout << "Please enter letter in the aplhabet:" << endl;
    cin >> letter;

    index =  ALPHABET.find(letter);

    if (index == string::npos)
        cout << "Error, letter not found" << endl;
    else
        cout << "The Position of " << letter << " in the string is: " << index << endl;

    return 0;
}

```
An if/else statement sounds good. And if that doesn't work, there are other multiple ways that it could.