logo codesdope

if else level 3 que 4

   Akshatha


Answers

  •    Aakhya Singh

    Check out this code.

    #include <stdio.h>
    
    int main(void) {
    	int age;
    	char sex, mar;
    	
    	/* input age */
    	printf("Enter age\n");
    	scanf("%d", &age);
    	
    	/* input sex */
    	printf("Enter sex : M or F\n");
    	scanf(" %c", &sex);
    	
    	/* input marital status */
    	printf("Enter marital status\n");
    	scanf(" %c", &mar);
    	
    	/* printing places of service */
    	if(sex == 'F')
    	{
    		printf("\nYou will work only in urban areas");
    	}
    	
    	if(sex == 'M')
    	{
    		if(age >= 20 && age < 40)
    		{
    			printf("\nYou may work anywhere");
    		}
    		else if(age >= 40 && age < 60)
    		{
    			printf("\nYou will work only in urban areas");
    		}
    		else
    		{
    			printf("\nERROR");
    		}
    	}
    	return 0;
    }
    

    • I have written the same code but it is not taking input for sex
      - Akshatha
    • Even if it takes it s not displaying the first condition instead it is displaying second condition.
      - Akshatha
    • Did you leave a space before %c in scanf while taking input?
      - Aakhya Singh

Share what you know
Write your answer
Close

Welcome.please sign up.

Close

Welcome.please login.