Question

Write a c# program named CheckMonth2 that prompts a user to enter a birth month and...

Write a c# program named CheckMonth2 that prompts a user to enter a birth month and day. Display an error message that says Invalid date if the month is invalid (not 1 through 12) or the day is invalid for the month (for example, not between 1 and 31 for January or between 1 and 29 for February). If the month and day are valid, display them with a message. For example, if the month entered is 2, and the day entered is 17, the output should be 2/17 is a valid birthday.

0 0
Add a comment Improve this question Transcribed image text
Answer #1


using System;
class CheckMonth2
{
static void Main()
{
int dd,mm; //declare dd to store day and mm to store month
//declare and initialize an array to assign the values of the dates of every month
int [] day = new int[12] {31,29,31,30,31,30,31,31,30,31,30,31};
//ask user to input the month
Console.WriteLine("Enter the month(1 to 12)");
//read the value of month from user and assign it to mm by using the concepts of type casting
mm=Convert.ToInt32(Console.ReadLine());
//ask user to input the day
Console.WriteLine("Enter the day");
//read the value of day from user and assign it to dd by using the concepts of type casting
dd=Convert.ToInt32(Console.ReadLine());
//condition to check the validity of month and day
if((mm>=1 && mm<=12) && (dd >=1 && dd<=day[mm-1]))
{ //write the valid message
Console.WriteLine("{0}/{1} is a Valid Birthday",mm,dd);
}
else
//write the invalid message
Console.WriteLine("Invalid date");
  

}
}

OUTPUT

Add a comment
Know the answer?
Add Answer to:
Write a c# program named CheckMonth2 that prompts a user to enter a birth month and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT