Related to my game again, i want to choose my options by typing the command. Yet, i am in a big difficulty, because switch() only accepts numbers, or it accepts one letter.
Everyone knows how switch works, i dont think i need to give an example.
Anyway, i will post the skeleton for the typing program i tried.
#include <iostream.h>
char TYPED;
int main()
{
cout<< "Type punch, kick, or bite." <<endl;
cin >> TYPED;
switch(TYPED)
{
case 'punch':
cout<< "You punch him." <<endl;
break;
case 'kick':
cout<< "You kick him." <<endl;
break;
case 'bite':
cout<< "You bite him." <<endl;
break;
default:
cout<< "I dont know how to do that." <<endl;
cout<<TYPED<<endl;
};
return 0;
}
Obviously, it doesnt work, or it doesnt work the way i want it to work. I tried to make an
enum attacks {null, punch, kick, bite};
But it doesnt work...
I have two options:
1) Use the switch with text like
case punch:
2) Use the switch with numbers like
case 1:
and the program must know it is number "1" because i typed "punch".
Both ways are fine for me, i just want to make it work!