back
Making a Computer Talk Back
You have learned how to create strings, now you are going to learn to program the computer to understand them. The way we will do that is by using a special function named strcmp(). The purpose of strcmp() is to compare strings. The computer compares the user's answer with the list of strings you have previously created. If there is a match, the program returns a value of zero. You can use this information to program a set response. You can use this feature to create the illusion that the computer is actually listening to the user and answering him or her.

Take a look at this example.

Copy and compile it. Notice how I had to make different variables for the different spellings of the user's reply. When you use strcmp(), "Yes," is different than, "YES," or "yes." There is a way around this problem. Take a look at this other example that utilizes strcmpi().

Strcmpi() ignores the case of the words.

Assignment
Use the strcmpi() function to engage the user in a dialogue. Write at least five questions. Anticipate at least three possible replys per question and prepare at least two different responses per reply.