Zodiac Sign Identifier using C#
Details: Zodiac Sign
Personality is a complex topic that is heavily influenced by the environment you are in. Therefore, your personality traits are different according to your zodiac sign. A person’s zodiac sign is based on astrology, which uses the movement of celestial bodies to determine a person’s character traits.
In this article, we will illustrate on how use Visual Studio 2019 utilizing the C# programming language to create a program that can identify your zodiac sign using your date of birth. We will work on date manipulation and not just the basic if and else statement or switch statement.
Guide: Zodiac Sign
1 – We start by opening a Windows Form Application in Microsoft Visual Studio by following the directives;
– Navigate to File
– Click on New Project
– Select Windows Application
2 – We can now add the following;
– A dateTimepicker labelled DTPDATEBIRTH for inputting the date of birth
– A button labelled Button1 for processing the zodiac sign
– A ListBox labelled ListBox1 for displaying the zodiac.
Your interface should be displayed like the image below.
3 – Declare a global array variable that can store the value of the zodiac sign in your code view.
string[] zodiac = new string[] {"Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces"};
4 – Insert the code below in Button1_Click
– Declare a string variable to format the datetimepicker to the name of the months.
string months = Strings.Format(DTPDATEBIRTH.Value, "MMMM");
Represent a formatted datetimepicker to a value of the day by declaring an integer variable.
int days = int.Parse(Strings.Format(DTPDATEBIRTH.Value, "dd"));
In other to insert the specific zodiac sign, you have to condition the months and the days.
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;
}
}
Finally, clear the Listbox.
ListBox1.Items.Clear()
Outputs: Zodiac Sign
Recommended Tutorial: RAM and CPU Meter in C# FREE