标题:用C编写星座匹配
只看楼主
寒露俞
Rank: 1
来 自:山西省
等 级:新手上路
帖 子:1
专家分:0
注 册:2016-6-2
结帖率:0
已结贴  问题点数:20 回复次数:3 
用C编写星座匹配
求助:在C中做一个输入一男一女的出生日期(阳历),得出每个人的星座,并进行匹配,最后以百分比的形式输出。
搜索更多相关主题的帖子: 出生日期 百分比 星座 
2016-06-02 16:04
grmmylbs
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:54
帖 子:1409
专家分:5845
注 册:2016-2-14
得分:20 
少了女生的双鱼,自行补上

程序代码:
#include "stdio.h"

enum start
{
    Capricorn,//摩羯
    bottle,//水瓶
    Pisces,//双鱼
    Aries,//白羊
    Taurus,//金牛
    Gemini,//双子
    Cancer,//巨蟹
    lion,//狮子
    Virgo,//处女
    Libra,//天枰
    scorpio,//天蝎
    sagittarius//射手
};

enum mon
{
    January = 1,
    February,
    March,
    April,
    May,
    June,
    July,
    August,
    September,
    October,
    November,
    December
};

int getstar(int mon, int day)
{
    switch (mon)
    {
        case January:
            if (day >= 20)
            {
                return bottle;
            }
            else
            {
                return Capricorn;
            }
        case February:
            if (day >= 19)
            {
                return Pisces;
            }
            else
            {
                return bottle;
            }
        case March:
            if (day >= 21)
            {
                return Aries;
            }
            else
            {
                return Pisces;
            }
        case April:
            if (day >= 20)
            {
                return Taurus;
            }
            else
            {
                return Aries;
            }
        case May:
            if (day >= 21)
            {
                return Gemini;
            }
            else
            {
                return Taurus;
            }
        case June:
            if (day >= 22)
            {
                return Cancer;
            }
            else
            {
                return Gemini;
            }
        case July:
            if (day >= 23)
            {
                return lion;
            }
            else
            {
                return Cancer;
            }
        case August:
            if (day >= 23)
            {
                return Virgo;
            }
            else
            {
                return lion;
            }
        case September:
            if (day >= 23)
            {
                return Libra;
            }
            else
            {
                return Virgo;
            }
        case October:
            if (day >= 24)
            {
                return scorpio;
            }
            else
            {
                return Libra;
            }
        case November:
            if (day >= 23)
            {
                return sagittarius;
            }
            else
            {
                return scorpio;
            }
        case December:
            if (day >= 22)
            {
                return Capricorn;
            }
            else
            {
                return sagittarius;
            }
        default:
            return Capricorn;
    }

}

int main()
{
    int a[12][12] = {
        {88,74,77,43,97,70,80,59,92,51,85,64},//摩羯--0
        { 69,87,60,72,41,91,58,78,64,96,51,82 },//水瓶--1
        { 100,100,100,100,100,100,100,100,100,100,100,100 },//双鱼--不全
        { 58,88,79,90,75,82,47,94,65,85,70,99 },//白羊
        { 93,66,81,68,88,72,75,25,97,57,78,61 },//金牛
        { 64,99,48,79,76,89,71,81,57,93,69,86 },//双子
        { 87,74,97,52,82,78,89,61,84,66,92,70 },//巨蟹
        { 77,84,62,97,56,79,69,87,72,81,45,92 },//狮子
        { 95,55,84,61,91,76,88,66,89,49,81,72 },//处女
        { 47,95,64,85,74,98,58,88,77,90,71,80 },//天枰
        { 76,57,92,60,80,68,97,65,84,73,87,47 },//天蝎
        { 75,78,44,92,70,81,65,98,58,86,68,89 },//射手
    };
    char star[12][12] = {"摩羯","水瓶","双鱼","白羊","金牛","双子","巨蟹","狮子","处女","天枰","天蝎","射手"};
    int man_mon, man_day, woman_mon, woman_day;
    int man_star, woman_star;

    printf("请输入男生生日(格式:月.日):");
    scanf("%d.%d",&man_mon,&man_day);
    printf("请输入女生生日(格式:月.日):");
    scanf("%d.%d", &woman_mon, &woman_day);
    man_star = getstar(man_mon, man_day);
    woman_star = getstar(woman_mon, woman_day);

    printf("男生的星座是%s,女生的星座是%s,\n", star[man_star], star[woman_star]);
    printf("他们的缘分是%d%%.\n", a[woman_star][man_star]);
}  
2016-06-03 12:01
pz2017
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2017-11-15
得分:0 
为什么这个程序我编译后出错了??不能运行
2017-11-21 00:45
pz2017
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2017-11-15
得分:0 
我一个一个单词对的,一个一个符号对的,都是正确的,就是编译了就出错,为啥啊???
2017-11-21 00:52



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




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

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