mercredi 4 février 2015

I'm not able to use scanf() in else statment

can we use scanf() function in else , like i used in this code. Bec i'm not able to enter value(char) for sex variable. so i want to why i'm not able to enter the value for sex variable ?



#include<stdio.h>
#include<conio.h>

void main()

{

clrscr();

int age;

char s,ms;

printf("Please enter M if you are married or U if you are un-married\n");

scanf("%c", &ms);



if(ms=='M')

printf("\nyou are recruted");


else if(ms=='U')

{


printf("\nenter sex- A for male & B for female\n");

scanf("%c",&s);

if(s=='A')

{

printf("\nEnter your age\n");

scanf("%d",age);

if(age>30)

printf("\nYou are selected");

else

printf("\nYour age is less for this job");

}

else if(s=='B')

{

printf("\nEnter your age\n");

scanf("%d",age);

if(age>25)

printf("\nyou are recruted");

else

printf("\nyour age is less to be recruted");

}

else

{

printf("Please enter A for male or B for female");

}

}

else

{

printf("PLEASE ENTER THE CORRECT VALUE\n please enter M for Married or U for un-married");

}

getch();

}


Output : Please enter M if you are married or U if you are un-married U enter sex A for male or B for female Please enter A for male or B for female


Aucun commentaire:

Enregistrer un commentaire