| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 885 人关注过本帖
标题:输入月份打出星座问题,大神帮忙看看,为什么后面输入前面行而后面不行了?
只看楼主 加入收藏
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
快速回复:输入月份打出星座问题,大神帮忙看看,为什么后面输入前面行而后面不行 ...
数据加载中...
 
   



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

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