C# Help Please Lookup the System.DateTime structure. This type contains a large
ID: 3602155 • Letter: C
Question
C# Help Please
Lookup the System.DateTime structure. This type contains a large amount of functionality that allows a user to perform all sorts of interesting operations with dates and times. Use System.DateTime along with System.Console to implement a simple C# program that does the following:
Ask the user for their birthday. It will probably easiest to ask year, then month, then day rather than parsing a combined string reliably.
Calculate the age of the user.
Check to see if the age of the user is impossible. For example, if the user is not yet born, output an error message. If the user claims to be 135 years old, then let them know that's not possible.
Output the age of the user to the console.
If it is the user's birthday, output a nice message.
Compute the user's astrological sign according to both the Western (sun sign) and Chinese astrological systems. If you are not familiar with these astrological systems, look them up on the web.
Output the computed signs to the console. Optionally output additional information (e.g. horoscope of the day) about the user based on their sign
Happy Birthday InstructionsLookup the System.DateTime structure. This type contains a large amount of functionality that allows a user to perform all sorts of interesting operations with dates and times. Use System.DateTime along with System.Console to implement a simple C# program that does the following:
Ask the user for their birthday. It will probably easiest to ask year, then month, then day rather than parsing a combined string reliably.
Calculate the age of the user.
Check to see if the age of the user is impossible. For example, if the user is not yet born, output an error message. If the user claims to be 135 years old, then let them know that's not possible.
Output the age of the user to the console.
If it is the user's birthday, output a nice message.
Compute the user's astrological sign according to both the Western (sun sign) and Chinese astrological systems. If you are not familiar with these astrological systems, look them up on the web.
Output the computed signs to the console. Optionally output additional information (e.g. horoscope of the day) about the user based on their sign
Explanation / Answer
using System;
class Program
{
static void Main()
{
DateTime todaysDate = DateTime.Now.Date;
int day = todaysDate.Day;
int month = todaysDate.Month;
int year = todaysDate.Year;
Console.Write("Enter your birth Year: ");
int birthYear = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter your birth Month: ");
int birthMonth = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter your birth Date: ");
int birthDay = Convert.ToInt32(Console.ReadLine());
int age = 0;
if ( year >= birthYear)
{
if(month == birthMonth)
{
if(day == birthDay)
{
age = (year - birthYear);
Console.Write("Happy Birthday!! :)");
}
else if(day < birthDay)
age = year - birthYear - 1;
else
age = year - birthYear;
}
else if (month < birthMonth)
age = year - birthYear - 1;
else
age = year - birthYear;
}
else
{
Console.Write("Incorrect birth date");
Environment.Exit(0);
}
if(age > 135)
Console.Write("Not possible");
else
Console.Write("Your age is: "+ age);
String value="";
if ((birthMonth == 1 && birthDay <= 20 )||(birthMonth == 12 && birthDay > 21 )) { value="Capricorn"; }
if ((birthMonth == 1 && birthDay > 20 )||(birthMonth == 2 && birthDay <= 19 )) { value="Aquarius"; }
if ((birthMonth == 2 && birthDay > 19 )||(birthMonth == 3 && birthDay <= 20 )) { value="Pisces"; }
if ((birthMonth == 3 && birthDay > 20 )||(birthMonth == 4 && birthDay <= 20 )) { value="Aries"; }
if ((birthMonth == 4 && birthDay > 20 )||(birthMonth == 5 && birthDay <= 21 )) { value="Taurus"; }
if ((birthMonth == 5 && birthDay > 21 )||(birthMonth == 6 && birthDay <= 22 )) { value="Gemini"; }
if ((birthMonth == 6 && birthDay > 22 )||(birthMonth == 7 && birthDay <= 22 )) { value="Cancer"; }
if ((birthMonth == 7 && birthDay > 22 )||(birthMonth == 8 && birthDay <= 23 )) { value="Leo"; }
if ((birthMonth == 8 && birthDay > 23 )||(birthMonth == 9 && birthDay <= 23 )) { value="Virgo"; }
if ((birthMonth == 9 && birthDay > 23 )||(birthMonth == 10 && birthDay <= 23 )) { value="Libra"; }
if ((birthMonth == 10 && birthDay > 23 )||(birthMonth == 11 && birthDay <= 22 )) { value="Scorpio"; }
if ((birthMonth == 11 && birthDay > 22 )||(birthMonth == 12 && birthDay <= 21 )) { value="Sagittarius"; }
Console.WriteLine("Your western zodiac sign is "+ value);
value="";
int x = (1901 - birthYear) % 12;
if (x == 1 || x == -11) {value = "Rat";}
if (x == 0) {value = "Ox";}
if (x == 11 || x == -1) {value = "Tiger";}
if (x == 10 || x == -2) {value = "Rabbit/Cat";}
if (x == 9 || x == -3) {value = "Dragon";}
if (x == 8 || x == -4) {value ="Snake";}
if (x == 7 || x == -5) {value = "Horse";}
if (x == 6 || x == -6) {value = "Sheep";}
if (x == 5 || x == -7) {value = "Monkey";}
if (x == 4 || x == -8) {value = "Cock/Phoenix";}
if (x == 3 || x == -9) {value = "Dog";}
if (x == 2 || x == -10) {value = "Boar";}
Console.WriteLine("Your chineese zodiac sign is "+ value);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.