How to properly use cases and case matching?

Hello, I am working on a Text adventure game.

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.

Example of my work:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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';
}
Last edited on
Topic archived. No new replies allowed.