I am trying to use a switch a return value for input by a player, in order to eliminate infinite loops when a word is entered while a number is needed and problems of the sort.
I have managed to get this to work on only 1/18 of my program, and it is frustrating me, because I am not sure what is wrong.
int main()
{
do
{
//intro is output here
//options are given, and asks for a number.
cin >> choice
switch ( userChoice(choice) )
{
case'1' :
{ //output result for this option }
case'2' :
{ //output result for this option }
case'3' :
{ //output result for this option }
}
}while( health > 0 );
}
void userChoice(string choice)
{
string choice[] = {"1", "2", "3"}
int size = 3;
int i = 0;
for( i = 0; i < size; i++ ) if( choice == choice[i] ) return'1';
for( i = 0; i < size; i++ ) if( choice == choice[i] ) return'2';
for( i = 0; i < size; i++ ) if( choice == choice[i] ) return'3';
}