Below is a C# console application that meets your requirements. It prompts the user to input three dates by individually requesting the year, month, and day. The application then validates whether each date is correct using .NET's DateTime type. If the date is valid, it determines the astrological zodiac sign corresponding to that date and prints it out. If the date is invalid, it will notify the user.
Before you run this code, please add the necessary error handling if you expect to deal with non-English locales or specific date formats.
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please enter three dates to find out their zodiac signs");
for (int i = 0; i < 3; i++)
{
Console.WriteLine($"Enter date #{i + 1}");
Console.Write("Year: ");
int year = int.Parse(Console.ReadLine());
Console.Write("Month: ");
int month = int.Parse(Console.ReadLine());
Console.Write("Day: ");
int day = int.Parse(Console.ReadLine());
try
{
DateTime date = new DateTime(year, month, day);
Console.WriteLine($"Date Entered: {date.ToShortDateString()}");
Console.WriteLine($"Zodiac Sign: {GetZodiacSign(date)}");
}
catch (ArgumentOutOfRangeException)
{
Console.WriteLine("Invalid date entered. Please try again.");
}
}
}
private static string GetZodiacSign(DateTime date)
{
int day = date.Day;
int month = date.Month;
if ((month == 3 && day >= 21) || (month == 4 && day <= 19))
return "Aries";
if ((month == 4 && day >= 20) || (month == 5 && day <= 20))
return "Taurus";
if ((month == 5 && day >= 21) || (month == 6 && day <= 20))
return "Gemini";
if ((month == 6 && day >= 21) || (month == 7 && day <= 22))
return "Cancer";
if ((month == 7 && day >= 23) || (month == 8 && day <= 22))
return "Leo";
if ((month == 8 && day >= 23) || (month == 9 && day <= 22))
return "Virgo";
if ((month == 9 && day >= 23) || (month == 10 && day <= 22))
return "Libra";
if ((month == 10 && day >= 23) || (month == 11 && day <= 21))
return "Scorpio";
if ((month == 11 && day >= 22) || (month == 12 && day <= 21))
return "Sagittarius";
if ((month == 12 && day >= 22) || (month == 1 && day <= 19))
return "Capricorn";
if ((month == 1 && day >= 20) || (month == 2 && day <= 18))
return "Aquarius";
if ((month == 2 && day >= 19) || (month == 3 && day <= 20))
return "Pisces";
return "Unknown";
}
}
This program:
- Asks users to input each part of the date (year, month, day) individually,
- Tries to create a
DateTime object with the user's inputs,
- Validates date correctness with the automatic checking in
DateTime constructor for out-of-range values,
- Determines the zodiac sign by defining the ranges of days and months corresponding to each sign,
- Handles any errors in date input by catching
ArgumentOutOfRangeException and informing the user about the invalid date.
Make sure the input is from a correct locale setup (e.g., Gregorian calendar). If you need to support different calendars or date formats, additional checks and settings will be required.