Hi I am implementing a function that check if user is a man or woman.
But it does not worl properly.

I press e for example and appears two times
Please press m/M for Man
w/W for

Also sometimes w/W/m/M are not recognised and appears the above.

My cose is :

char ask_if_man_or_woman()
{
     char choice_char;
     
     printf("Please answer me (w/m)\n");
     scanf("%c",&choice_char);   
 
     while((choice_char!='w')&&(choice_char!='W')&&(choice_char!='m')&&(choice_char!='M'))
     {
            printf("\n\t Please press m/M for Man\n");
            printf("\t              w/W for Woman\n\n");    
            
            scanf("%c",&choice_char);   
         
            printf("\n");
     }
                   
return choice_char;      
}

Any ideas please ????

char ask_if_man_or_woman()
{
  int choice_char;

  do
  {
printf("\n\t Please press m/M for Man\n");
printf("\t w/W for Woman\n\n");
choice_char=getchar();


  }while(choice_char==('w' || 'W' || 'm' || 'M'));
  return choice_char;
}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

char ask_if_man_or_woman()
{
      int choice_char;

      do
      {
    printf("\n\t Please press m/M for Man\n");
    printf("\t w/W for Woman\n\n");
    choice_char=getchar();


      }while(choice_char==('w' || 'W' || 'm' || 'M'));
      return choice_char;
}

Thanks a lot
The problem solved using fflush(stdin)

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This question has already been answered. Start a new discussion instead.