I am using switch case for my boolean expression with answer either yes or no. But i want it to loop back if the answer is invalid. How do i use if or while loop with answer in Character can varies up as 'y' 'Y' 'n' 'N'? could the below if statement work?
if (mstatus != 'y', 'Y', 'N', 'n')
{
switch(mstatus)
case 'y':
printf("You have answer yes for married");
break;
case 'Y':
printf("You have answer yes for married");
break;
case 'n':
printf("You have answer no for married");
break;
case 'N':
printf("You have answer no for married");
break;
}
else
{
default:
printf("please re-enter a valid answer");
scanf(" %c", &mstatus);
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire