标题:输入月份打出星座问题,大神帮忙看看,为什么后面输入前面行而后面不行了?
只看楼主
traveller、z
Rank: 2
等 级:论坛游民
帖 子:49
专家分:34
注 册:2014-12-2
得分:0 
回复 5楼 逍风
我改了下,但大部分主题还是你的建议:
#include<stdio.h>
#include <windows.h>
void test(int year, int m, int d);
int main()
{
    int year, cha, m, d,choose;
    printf("\n");
    printf("输入出生年份,月份及日期:");
    scanf("%d %d %d", &year, &m, &d);
    test(year, m, d);
    scanf("%d", &choose);
    if (choose == 1)
        main();
    else
        exit(0);
}
void test(int year, int m, int d)
{
    int choose;
    int cha;
    cha = (year - 1985) % 12;
    if (cha < 0)
        cha = 12 + cha;
    switch (cha)
    {
    case 0:printf("牛年,生肖:属牛\n"); break;
    case 1:printf("虎年,生肖:属虎\n"); break;
    case 2:printf("兔年,生肖:属兔\n"); break;
    case 3:printf("龙年,生肖:属龙\n"); break;
    case 4:printf("蛇年,生肖:属蛇\n"); break;
    case 5:printf("马年,生肖:属马\n"); break;
    case 6:printf("羊年,生肖:属羊\n"); break;
    case 7:printf("猴年,生肖:属猴\n"); break;
    case 8:printf("鸡年,生肖:属鸡\n"); break;
    case 9:printf("狗年,生肖:属狗\n"); break;
    case 10:printf("猪年,生肖:属猪\n"); break;
    case 11:printf("鼠年,生肖:属鼠\n"); break;
    }
    switch (m)
    {
    case 1:{if (d < 20)
        printf("星座:魔蝎座\n");
           else
               printf("星座:水瓶座\n");
        break; }
    case 2:{if (d < 19)
        printf("星座:水瓶座\n");
           else
               printf("星座:双鱼座\n");
        break; }
    case 3:{if (d < 21)
        printf("星座:双鱼座\n");
           else
               printf("星座:白羊座\n");
        break; }
    case 4:{if (d < 20)
        printf("星座:白羊座\n");
           else
               printf("星座:金牛座\n");
        break; }
    case 5:{if (d < 21)
        printf("星座:金牛座\n");
           else
               printf("星座:双子座\n");
        break; }
    case 6:{if (d < 22)
        printf("星座:双子座\n");
           else
               printf("星座:巨蟹座\n");
        break; }
    case 7:{if (d < 23)
        printf("星座:巨蟹座\n");
           else
               printf("星座:狮子座\n");
        break; }
    case 8:{if (d < 23)
        printf("星座:狮子座\n");
           else
               printf("星座:处女座");
        break; }
    case 9:{if (d < 23)
        printf("星座:处女座\n");
           else
               printf("星座:天秤座\n");
        break; }
    case 10:{if (d < 24)
        printf("星座:天秤座\n");
            else
                printf("星座:天蝎座\n");
        break; }
    case 11:{if (d < 23)
        printf("星座:天蝎座\n");
            else
                printf("星座:射手座\n");
        break; }
    case 12:{if (d < 22)
        printf("星座:射手座\n");
            else
                printf("星座:魔蝎座\n");
        break; }
    }
    printf("\n");
    printf("是否继续查询:1.继续 0.取消:");
}

学习!!!
2015-03-18 17:04
traveller、z
Rank: 2
等 级:论坛游民
帖 子:49
专家分:34
注 册:2014-12-2
得分:0 
再改下
#include<stdio.h>
#include <windows.h>
void test(int year)
{
    int cha;
    cha = (year - 1985) % 12;
    if (cha < 0)
        cha = 12 + cha;
    switch (cha)
    {
    case 0:printf("牛年 生肖:属牛\n"); break;
    case 1:printf("虎年 生肖:属虎\n"); break;
    case 2:printf("兔年 生肖:属兔\n"); break;
    case 3:printf("龙年 生肖:属龙\n"); break;
    case 4:printf("蛇年 生肖:属蛇\n"); break;
    case 5:printf("马年 生肖:属马\n"); break;
    case 6:printf("羊年 生肖:属羊\n"); break;
    case 7:printf("猴年 生肖:属猴\n"); break;
    case 8:printf("鸡年 生肖:属鸡\n"); break;
    case 9:printf("狗年 生肖:属狗\n"); break;
    case 10:printf("猪年 生肖:属猪\n"); break;
    case 11:printf("鼠年 生肖:属鼠\n"); break;
    }
}
void must(int m, int d)
{
    switch (m)
    {
    case 1:{if (d < 20)
        printf("星座:魔蝎座\n");
           else
               printf("星座:水瓶座\n");
        break; }
    case 2:{if (d < 19)
        printf("星座:水瓶座\n");
           else
               printf("星座:双鱼座\n");
        break; }
    case 3:{if (d < 21)
        printf("星座:双鱼座\n");
           else
               printf("星座:白羊座\n");
        break; }
    case 4:{if (d < 20)
        printf("星座:白羊座\n");
           else
               printf("星座:金牛座\n");
        break; }
    case 5:{if (d < 21)
        printf("星座:金牛座\n");
           else
               printf("星座:双子座\n");
        break; }
    case 6:{if (d < 22)
        printf("星座:双子座\n");
           else
               printf("星座:巨蟹座\n");
        break; }
    case 7:{if (d < 23)
        printf("星座:巨蟹座\n");
           else
               printf("星座:狮子座\n");
        break; }
    case 8:{if (d < 23)
        printf("星座:狮子座\n");
           else
               printf("星座:处女座");
        break; }
    case 9:{if (d < 23)
        printf("星座:处女座\n");
           else
               printf("星座:天秤座\n");
        break; }
    case 10:{if (d < 24)
        printf("星座:天秤座\n");
            else
                printf("星座:天蝎座\n");
        break; }
    case 11:{if (d < 23)
        printf("星座:天蝎座\n");
            else
                printf("星座:射手座\n");
        break; }
    case 12:{if (d < 22)
        printf("星座:射手座\n");
            else
                printf("星座:魔蝎座\n");
        break; }
    }
    printf("\n");
    printf("是否继续查询:1.继续 0.取消:");
}
int main()
{
    int year, cha, m, d, choose;
    printf("\n");
    printf("输入出生年份,月份及日期:");
    scanf("%d %d %d", &year, &m, &d);
    test(year);
    must(m, d);
    scanf("%d", &choose);
    if (choose == 1)
        main();
    else
        exit(0);
}

学习!!!
2015-03-18 19:23



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-442720-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023680 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved