Zodiac Sign Identifier Using C#


identify zodiac sign in c#

This is a tutorial, that will teach you how to make a program that will identify your zodiac sign with regards to your date of birth in Visual Studio 2010 using C# language. It is not just any ordinary if and else statement, or switch statement but it can undergo a date manipulation.

Let’s start this tutorial!

1. Now start with creating a Windows Form Application in C# for this tutorial by following the following steps in Microsoft Visual Studio 2010: Go to File, click New Project, and choose Windows Application.

2. Then, add dateTimepicker named DTPDATEBIRTH for inputting of your date of birth, a button named Button1 for processing your zodiac sign, and a ListBox named ListBox1 for displaying your zodiac. Design your interface like this:

design

3. In your code view, declare a global array variable to store the value of the zodiac signs on it.

string[] zodiac = new string[] {"Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces"};

4. In your Button1_Click, put this code below.

Declare a string variable to format the datetimepicker to the name of the months.

string months = Strings.Format(DTPDATEBIRTH.Value, "MMMM");

Declare an integer variable represent a formatted the datetimepicker to a value of the day.

int days = int.Parse(Strings.Format(DTPDATEBIRTH.Value, "dd"));

Conditioning the months and the days inorder to put the specific zodiac zign.

switch (months)
            {
                case "January":
                    if (days >= 1 & days <= 19)
                    {
                        //ADDING A ZODIAC SIGN IN THE LIST BOXS.
                        ListBox1.Items.Add("Zodiac Sign :" + zodiac[9]);
                    }
                    else
                    {
                        ListBox1.Items.Add("Zodiac Sign :" + zodiac[10]);
                    }
                    break;
                case "February":
                    if (days >= 1 & days <= 18)
                    {
                        ListBox1.Items.Add("Zodiac Sign :" + zodiac[10]);
                    }
                    else
                    {
                        ListBox1.Items.Add("Zodiac Sign :" + zodiac[11]);
                    }
                    break;
                case "March":
                    if (days >= 21)
                    {
                        ListBox1.Items.Add("Zodiac Sign :" + zodiac[0]);
                    }
                    else
                    {
                        ListBox1.Items.Add("Zodiac Sign :" + zodiac[11]);
                    }
                    break;
                case "April":
                    if (days >= 1 & days <= 19)
                    {
                        ListBox1.Items.Add("Zodiac Sign :" + zodiac[0]);
                    }
                    else
                    {
                        ListBox1.Items.Add("Zodiac Sign :" + zodiac[1]);
                    }
                    break;
                case "May":
                    if (days >= 1 & days <= 20)
                    {
                        ListBox1.Items.Add("Zodiac Sign :" + zodiac[1]);
                    }
                    else
                    {
                        ListBox1.Items.Add("Zodiac Sign :" + zodiac[2]);
                    }
                    break;
                case "June":
                    if (days >= 1 & days <= 21)
                    {
                        ListBox1.Items.Add("Zodiac Sign :" + zodiac[2]);
                    }
                    else
                    {
                        ListBox1.Items.Add("Zodiac Sign :" + zodiac[3]);
                    }
                    break;
                case "July":
                    if (days >= 1 & days <= 22)
                    {
                        ListBox1.Items.Add("Zodiac Sign :" + zodiac[3]);
                    }
                    else
                    {
                        ListBox1.Items.Add("Zodiac Sign :" + zodiac[4]);
                    }
                    break;
                case "August":
                    if (days >= 1 & days <= 22)
                    {
                        ListBox1.Items.Add("Zodiac Sign :" + zodiac[4]);
                    }
                    else
                    {
                        ListBox1.Items.Add("Zodiac Sign :" + zodiac[5]);
                    }
                    break;
                case "September":
                    if (days >= 1 & days <= 22)
                    {
                        ListBox1.Items.Add("Zodiac Sign :" + zodiac[5]);
                    }
                    else
                    {
                        ListBox1.Items.Add("Zodiac Sign :" + zodiac[6]);
                    }
                    break;
                case "October":
                    if (days >= 1 & days <= 22)
                    {
                        ListBox1.Items.Add("Zodiac Sign :" + zodiac[6]);
                    }
                    else
                    {
                        ListBox1.Items.Add("Zodiac Sign :" + zodiac[7]);
                    }
                    break;
                case "November":
                    if (days >= 1 & days <= 21)
                    {
                        ListBox1.Items.Add("Zodiac Sign :" + zodiac[7]);
                    }
                    else
                    {
                        ListBox1.Items.Add("Zodiac Sign :" + zodiac[8]);
                    }
                    break;
                case "December":
                    if (days >= 1 & days <= 21)
                    {
                        ListBox1.Items.Add("Zodiac Sign :" + zodiac[8]);
                    }
                    else
                    {
                        ListBox1.Items.Add("Zodiac Sign :" + zodiac[9]);
                    }
                    break;
            }
 
        }

Lastly, clear the Listbox.

Output:

output



Sharing is caring!

Facebook Comments

Leave a Reply