根据C#出生两个日期占星术恒星之间的兼容性 [英] compatibility between astrological stars according to two dates of birth in c#

查看:108
本文介绍了根据C#出生两个日期占星术恒星之间的兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于我的小项目的问题这是基于通过检查出生两个日期查看两台占星恒星之间的相容性(例如:第一个人的出生日期(1-19(第一位数代表月份和2位表示日期))进入第二个则人的DOB accordingly.my代码工作正常,当我进入出生两个日期意味着它是在告诉根据出生日期输入月份,日期和占星术的明星。但是当我试图找到两个特定恒星它只是计算的第一个结果之间的兼容性如果else语句,如果结果第一的if else控制结构没有找到它没有跳到下一个else if语句可,它直接跳到最后一个else语句..
I是第一次在这里张贴问题,请me..if谁能帮助可以在这里是我的代码示例!

i have a question about my little project which is based on the checking the compatibility between two astrological stars by checking two dates of birth (e.g: date of birth of first person(1-19(first digit represents month and 2nd digit represents date)) then second person's dob is entered accordingly.my code is working properly when i am entering two dates of birth means it is telling the month,date and astrological star according to the dates of birth entered. but when i am trying to find the compatibility between two specific stars it is only calculating the first result in if else statement,if result in first if else control structure is not found it is not jumping to the next else if statement, it is directly jumping to the last else statement.. i am first time posting the question here please help me..if anyone can here is my code sample!!!

DateTime date = Convert.ToDateTime(Console.ReadLine());
            Console.WriteLine("Month:" + date.Month);
            Console.WriteLine("Day:" + date.Day);
            month = date.Month;
            day = date.Day;
            month1=date1.Month;
            day1=date1.Day;
string[] stringArr = { "January", "February", "march", "April", "may", "June", "July", "august", "September", "October", "November", "December"};
switch (month)
        {
            case 1:
                if (day <= 19)
                    return "Capricorn";
                else
                    return "Aquarius";

            case 2:
                if (day <= 18)
                    return "Aquarius";
                else
                    return "Pisces";
            case 3:
                if (day <= 20)
                    return "Pisces";
                else
                    return "Aries";
            case 4:
                if (day <= 19)
                    return "Aries";
                else
                    return "Taurus";
            case 5:
                if (day <= 20)
                    return "Taurus";
                else
                    return "Gemini";
            case 6:
                if (day <= 20)
                    return "Gemini";
                else
                    return "Cancer";
            case 7:
                if (day <= 22)
                    return "Cancer";
                else
                    return "Leo";
            case 8:
                if (day <= 22)
                    return "Leo";
                else
                    return "Virgo";
            case 9:
                if (day <= 22)
                    return "Virgo";
                else
                    return "Libra";
            case 10:
                if (day <= 22)
                    return "Libra";
                else
                    return "Scorpio";
            case 11:
                if (day <= 21)
                    return "Scorpio";
                else
                    return "Sagittarius";
            case 12:
                if (day <= 21)
                    return "Sagittarius";
                else
                    return "Capricorn";

        return "";
       }



日期同时计算。
问题是在这里。

date of birth for another person is calculated simultaneously. problem is here..

if (ob.month.Equals(1) && ob1.month1.Equals(1))
{

    if (ob.day <= 19 && ob1.day1 <= 19)
    {
        Console.WriteLine("Compatibility of Capricon with Capricon");
    }
    // else if (ob.day <= 19 && ob1.day1 > 19)
    else
    {
        Console.WriteLine("Compatibility of Capricon with Aquarius");
    }
}

else if (ob.month.Equals(1) && ob.month1.Equals(2))
{

    if (ob.day <= 19 && ob1.day1 <= 18)
    {
        Console.WriteLine("Compatibility of Capricon with Aquarius");
    }
    //else if (ob.day <= 19 && ob1.day1 > 18)
    else
    {
        Console.WriteLine("Compatibility of Capricon with Pisces");
    }
}
else if (ob.month.Equals(1) && ob.month1.Equals(3))
{
    if (ob.day <= 19 && ob.day1 <= 20)
    {
        Console.WriteLine("Compatibility of Capricon with Pisces");
    }
    else
    {
        Console.WriteLine("Compatibility of Capricon with Aries");
    }
}
else
    {consle.writeLine("invalid");
    }



这段代码是给予回应只是第一个,如果else语句没有其他的if else ..
请帮助me..how应该怎么解决这个问题!

this code is giving response just to 1st if else statement not to other if else.. please help me..how should i solve this problem!!!

推荐答案

您使它很难办法。更简单。

You make it very difficult way. Make it simpler.

class Program
{
    enum ZodiacSign
    {
        Aries, // March 21 - April 20
        Taurus, // April 21 - May 21
        Gemini, // May 22 - June 21
        Cancer, // June 22 - July 22
        Leo, // July 23 -August 21
        Virgo, // August 22 - September 23
        Libra, // September 24 - October 23
        Scorpio, // October 24 - November 22
        Sagittarius, // November 23 - December 22
        Capricorn, // December 23 - January 20
        Aquarius, // January 21 - February 19
        Pisces // February 20- March 20
    }

    static ZodiacSign BirthdayToZodiacSign(DateTime birthday)
    {
        var periodEndList = new[] {
            new { PeriodEnd = new DateTime(birthday.Year, 1, 20), ZodiacSign = ZodiacSign.Capricorn },
            new { PeriodEnd = new DateTime(birthday.Year, 2, 19), ZodiacSign = ZodiacSign.Aquarius },
            new { PeriodEnd = new DateTime(birthday.Year, 3, 20), ZodiacSign = ZodiacSign.Pisces },
            new { PeriodEnd = new DateTime(birthday.Year, 4, 20), ZodiacSign = ZodiacSign.Aries },
            new { PeriodEnd = new DateTime(birthday.Year, 5, 21), ZodiacSign = ZodiacSign.Taurus },
            new { PeriodEnd = new DateTime(birthday.Year, 6, 21), ZodiacSign = ZodiacSign.Gemini },
            new { PeriodEnd = new DateTime(birthday.Year, 7, 22), ZodiacSign = ZodiacSign.Cancer },
            new { PeriodEnd = new DateTime(birthday.Year, 8, 21), ZodiacSign = ZodiacSign.Leo },
            new { PeriodEnd = new DateTime(birthday.Year, 9, 23), ZodiacSign = ZodiacSign.Virgo },
            new { PeriodEnd = new DateTime(birthday.Year, 10, 23), ZodiacSign = ZodiacSign.Libra },
            new { PeriodEnd = new DateTime(birthday.Year, 11, 22), ZodiacSign = ZodiacSign.Scorpio },
            new { PeriodEnd = new DateTime(birthday.Year, 12, 22), ZodiacSign = ZodiacSign.Sagittarius }
        };

        foreach (var periodEnd in periodEndList)
            if (birthday <= periodEnd.PeriodEnd)
                return periodEnd.ZodiacSign;
        return ZodiacSign.Capricorn;
    }

    static string GenerateCompatibilityString(DateTime birthday1, DateTime birthday2)
    {
        return string.Format("Compatibility of {0} with {1}", BirthdayToZodiacSign(birthday1), BirthdayToZodiacSign(birthday2));
    }

    static void Main(string[] args)
    {
        Console.WriteLine(GenerateCompatibilityString(new DateTime(2014, 1, 1), new DateTime(2014, 6, 7)));
    }
}

这篇关于根据C#出生两个日期占星术恒星之间的兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆