You should do a bit of studying on character types first.
char is a single character type. If you want to get a sentence or word, you need to use either
char* or char[N] (array of characters, also known as a c-string, where N-1 is the maximum number of characters), or
string (though you'll then need to
#include <string> ).
If you use
char*, you then need to use
char* str = new char[N] where N-1 is the maximum number of characters that'll fit. In the if's, it then also has to become
if(!strcmp(str,"ir")). At the end of the code, you'll then need a
delete[] str;
Using strings, everything is simpler. All the memory allocation is done for you and it has an overloaded == operator which means that simply doing
1 2
|
string str="bla";
if(str=="ir")
|
will work just fine. However,
<string> is a purely C++ method, so it might not be valid for your class if all you're taught is C (that was my case).
Also note that I used double-quotes instead of single-quotes. That's because single-quotes stand for single characters. For two or more characters, you need to use double-quotes, which is the representation of c-strings.