c语言 8 - 5

1、

#include <stdio.h>

enum info { Gender, Season, Age, Invalid};

void gender(void)
{
    puts("male.\n");
}

void season(void)
{
    puts("summer.\n");
}

void age(void)
{
    puts("30.\n");
}

enum info select(void)
{
    enum info tmp;
    do
    {
        puts("0: gender  1: season  2: age 3: quit.");
        printf("tmp = "); scanf("%d", &tmp);
    }
    while(tmp < Gender || tmp > Invalid);
    return tmp;
}

int main(void)
{
    enum info a;
    do
    {
        switch(a = select())
        {
            case Gender : gender(); break;
            case Season : season(); break;
            case Age    : age(); break;
        }
    }
    while(a != Invalid);
    return 0;
}

 

posted @ 2021-05-22 17:35  小鲨鱼2018  阅读(66)  评论(0编辑  收藏  举报