none
c# program to calculate age and astrlogical sign RRS feed

  • Question

  •  Use System.DateTime along with System.Console to implement a simple C# program that does the following:

    1.Ask the user for their birthday.  It will probably easiest to ask year, then month, then day rather than parsing a combined string reliably.
    2.Calculate the age of the user.
    3.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.
    4.Output the age of the user to the console.
    5.If it is the user's birthday, output a nice message.
    6.Compute the user's astrological sign.
    7.Output the computed signs to the console. 
    Monday, August 31, 2015 1:29 AM

Answers

  • Hi anafana,

    Based on your description, below is the key code(get age from birthday).

    public static int CalculateAge(DateTime birthDay)
    {
        int years = DateTime.Now.Year - birthDay.Year;
        if ((birthDay.Month > DateTime.Now.Month) || (birthDay.Month == DateTime.Now.Month && birthDay.Day > DateTime.Now.Day))
            years--;
        return years;
    }

    If you have further question, please feel free let us know.

    Best Regards,
    Li Wang

    Thursday, September 3, 2015 8:44 AM
    Moderator

All replies

  • You have posted what your assignment is, what have you done so far? We can help with any specific problems, but you must realise that getting someone else to do your assignment for you is not allowed.
    Monday, August 31, 2015 2:06 AM
  • Hi anafana,

    Based on your description, below is the key code(get age from birthday).

    public static int CalculateAge(DateTime birthDay)
    {
        int years = DateTime.Now.Year - birthDay.Year;
        if ((birthDay.Month > DateTime.Now.Month) || (birthDay.Month == DateTime.Now.Month && birthDay.Day > DateTime.Now.Day))
            years--;
        return years;
    }

    If you have further question, please feel free let us know.

    Best Regards,
    Li Wang

    Thursday, September 3, 2015 8:44 AM
    Moderator