Home>

I made a text using an enumerated type by myself, tried it, and moved it, but I can't move the code as I expected.
I tried and tried it, but I didn't understand why it was solved.

Why isn't it displayed without enumeration with enum?
I don't know, so please explain.

Problems i am experiencing
typedef enum {MALE = 1, FEMALE = 2} Gender;


And the number must be written as =

if (age>= 13&&gender_m)


Is not working

Applicable source code
# include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
typedef char String [1024];
int main (void)
{
        typedef enum {MALE, FEMALE} Gender;// this statement
        String sage;
        String snumber;
        printf ("Please input age. \ n");
        scanf ("% 1023s% * [^ \ n]% * c", sage);
        int age = atoi (sage);
        printf ("Please fill in the gender by number: mail 1, female 2 \ n");
        scanf ("% 1023s% * [^ \ n]% * c", snumber);
        int number = atoi (snumber);
        if (number == 1)
        {
                Gender gender_m = MALE;
                if (age>= 13&&gender_m)
                {
                        printf ("You are not a boy! \ n");
                }
                else if (age<13&&gender_m)
                {
                        printf ("You are a boy !! \ n");
                }
        }
        else if (number == 2)
        {
                Gender gender_f = FEMALE;
                if (age>= 13&&gender_f)
                {
                        printf ("You are not a girl !! \ n");
                }
                else if (age<13&&gender_f)
                {
                        printf ("You are a girl !! \ n");
                }
        }
        else
        {
                printf ("Error \ n");
        }
/ * Isn't it impossible to have a variable in the label?
        switch (number)
        {
                case 1:
                        Gender gender_m = MALE;
                        break;
                case 2:
                        Gender gender_f = FEMALE;
                        break;
                default:
                        printf ("Eroor! \ n");
        }
* /
/ * Tried sentences

        if (number == 1)
        {
                if (age>= 13&&number == 1)
                {
                        printf ("No m !! \ n");
                }
                else if (age<13&&number == 1)
                {
                        printf ("Yes m !! \ n");
                }
        }
        else if (number == 2)
        {
                if (age>= 13&&number == 2)
                {
                        printf ("No f !! \ n");
                }
                else if (age<13&&number == 2)
                {
                        printf ("Yes f !! \ n");
                }
        }
        else
        {
                printf ("Error \ n");
        }
        * /


        return 0;
}
Supplemental information

Writing with vim

Corrections

Fix typographical errors

c
  • Answer # 1

    Try displaying gender_m. Is it 0 (ie FALSE)?

  • Answer # 2

    First of all, what kind of state do you mean by not working?

    Also

      

    if (age>= 13&&gender_f)

    What is the intention of this if statement?

    if (age>= 13&&gender_f == FEMALE)

    If you don't,


    enum starts at 0 if there is no special notation

      

    if (age>= 13&&gender_f)

    It ’s just gender_f with a zero in it

  • Answer # 3

    Gender gender_m = MALE;
                    if (age>= 13&&gender_m)


    Is unclear. This is becauseMALEis0

    int gender_m = 0;
                    if (age>= 13&&gender_m)


    Is the same.
    In the first place, it isif (number == 1)before that, so when you come here, you are determined to be a man. Simply

    if (age>= 13)


    Is it okay?

  • Answer # 4

    I do n’t understand the intention of the question,

    typedef enum {MALE, FEMALE} Gender;

    means

    enum {MALE, FEMALE}
    It's a syntax that adds anGenderalias to the type

    .