Close
Close

if else level 3 que 4

   Akshatha


Answers

  •   

    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

Ask Yours
Post Yours
Write your answer