i am creating a program which requires user to enter their marital status. i want to be able to ask them Yes or No and then use " if " statements . my code just skips the if part and prints the else part.
#include<stdio.h>
int main(void)
{
int age;
char marr;
printf("Please enter your age: \n");
scanf_s("%d",&age);
getchar();// getchar() is being used to clear any buffer of any remaining keystrokes that might stll be stored.
printf("Are you married ? (y/n)\n");
scanf_s("%c", &marr);
if (marr == 'y')
printf("Married\n");
else
printf("Unmarried\n");
}
for some reason, whatever i input, i still get the output as ' unmarried ' no idea why. Please help . Thank You
Aucun commentaire:
Enregistrer un commentaire