Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Taking String as input and checking for Value

$
0
0
Hello, I'm trying to create a program where the user selects a level of a game (the game program works fine). There are three levels: ONE, TWO, and THREE (case sensitive). The idea is that if the user inputs one of those levels, then a switch loop will commence to display the text for the appropiate level. Yet no matter what I input, it goes straight into the error catch while loop. Does someone see the problem, I'm sure it's basic...

This is a function, but all I have in my main is the function call. Thanks!

int promptUser(char s)
{
  //char s;
  int levelChoice;
  char input[10];
  printf("\nWELCOME TO THE GAME\n");
  printf("Which area do you want to start in first?\n(ONE)- Castle\n(TWO)- Swamp\n(THREE)- Forest\n");
  scanf("%s", input);
  
  
  
  while (strcmp(input, "ONE") != 0 || strcmp(input, "TWO") != 0 || strcmp(input, "THREE") != 0 )
  {
    printf("Sorry, you must enter the level number in ALL CAPS\nPlease try again.\n");
    scanf("%s", input);
  }
  
    switch(levelChoice)
    {
      case 1:
	printf("Welcome to the castle!\n");
	levelChoice = 1;
	break;
      
      case 2:
	printf("Welcome to the swamp!\n");
	levelChoice = 2;
	break;
      
      case 3:
	printf("Welcome to the forest!\n");
	levelChoice = 3;
	break;
    }
   
  
  return levelChoice;
}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>