#include <iostream>
#include <string>
#include <cctype>
using namespace std;
void main()
{
// build command map
string commands[] = {
"east", "north", "south", "west" // ... all the command word with lower case
};
const int nCount = sizeof(commands)/sizeof(string);
// receive command from console and convert to lowercase
string strCmd;
cin >> strCmd;
for(int i=0; i<strCmd.size(); i++)
strCmd[i] = _tolower(strCmd[i]);
// map command to int
for(i=0; i<nCount; i++)
{
if(strCmd == commands[i])
break;
}
// execute command
switch(i)
{
case string:
cout << "East" << endl;
break;
case string:
cout << "North" << endl;
break;
case string:
cout << "West" << endl;
break;
case string:
cout << "South" << endl;
break;
default:
cout << "Unknow command." << endl;
}
}
someone want to explain whats going on in this to me?... i understand a little but it would be great to know it all... just reply please