Question

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

Write a 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.

(answer in c#)

-----------------------------------------------------------------------------------------------------------------------------------

using System;
using static System.Console;
class CheckMonth2
{
static void Main()
{
// Write your main here
}
}

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

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

using static System.Console;
using System;

class CheckMonth2
{
static void Main()
{
int month, day;
//Prompts a user to enter a birth month and day.
Console.Write("Please enter your month of birth: ");
month = Convert.ToInt32(Console.ReadLine());
Console.Write("Please enter your day of birth: ");
day = Convert.ToInt32(Console.ReadLine());
//Display an error message if the month is invalid (not 1 through 12)
//or the day is invalid for the month
//If the month and day are valid, display them with a message.
if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
if(day <= 31 && day >= 1)
Console.WriteLine(month+"/"+day+" is a valid birthday.");
else
Console.WriteLine("Invalid date");
else if(month == 4 || month == 6 || month == 9 || month == 11)
if(day <= 30 && day >= 1)
Console.WriteLine(month+"/"+day+" is a valid birthday.");
else
Console.WriteLine("Invalid date");
else if(month == 2)
if(day <= 29 && day >= 1)
Console.WriteLine(month+"/"+day+" is a valid birthday.");
else
Console.WriteLine("Invalid date");
else
Console.WriteLine("Invalid date");
  
}
}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Write a program named CheckMonth2 that prompts a user to enter a birth month and day....
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
  • Write a C# program that prompts a user to enter a birth month and day. Display...

    Write a C# program that prompts a user to enter a birth month and day. Display an error message 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.

  • Write a program in visual c# program named CheckMonth that prompts a user to enter a...

    Write a program in visual c# program named CheckMonth that prompts a user to enter a birth month. If the value entered is greater than 12 or less than 1, display an error message; otherwise, display the valid month with a message such as 3 is a valid month.

  • Write the program FindPatientRecords that prompts the user for an ID number, reads records from Patients.txt,...

    Write the program FindPatientRecords that prompts the user for an ID number, reads records from Patients.txt, and displays data for the specified record. If the record does not exist, display the following error message: No records found for p# using System; using static System.Console; using System.IO; class FindPatientRecords { static void Main() { // Your code here } }

  • Write the program FindPatientRecords that prompts the user for an ID number, reads records from Patients.txt,...

    Write the program FindPatientRecords that prompts the user for an ID number, reads records from Patients.txt, and displays data for the specified record. If the record does not exist, display the following error message: No records found for p# using System; using static System.Console; using System.IO; class FindPatientRecords { static void Main() { // Your code here } }

  • Write a program that prompts the user to enter a person's birth date in numeric form...

    Write a program that prompts the user to enter a person's birth date in numeric form (e.g. 8-27-1980) and outputs the date of birth in the format of month day, year (e.g. August 27, 1980). Your program must work for three types of exceptions - invalid day, invalid month and invalid year (year must be between 1915 and 2015). Make these as class driven exceptions. Use one try-catch block with separate catches for the exception classes to handle errors for...

  • In ruby Write a program that prompts the user to enter a year and first day...

    In ruby Write a program that prompts the user to enter a year and first day of the year, and displays the calendar table of that year. For example, if the user entered the year 2019, and 2 for Tuesday, January 1, 2019, your program should display the calendar for each month in the year 2019.

  • Write program that prompts the user to enter a person's date of birth in numeric form...

    Write program that prompts the user to enter a person's date of birth in numeric form such as 8-27-1980. The program then outputs the date of birth in the form: August 27, 1980. Your program must contain at least two exception classes: invalidDay and invalidMonth. If the user enters an invalid value for day, then the program should throw and catch an invalidDay object. Similar conventions for the invalid values of month and year. (Note that your program must handle...

  • 1. Write a program that prompts the user to enter three integers and display the integers...

    1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. For example: Input Result 140 -5 10 Enter a number: Enter a number: Enter a number: -5, 10, 140 import java.util.Scanner; public class Lab01 { public static void main(String[] args) { Scanner input = new Scanner(System.in);    } } ---------------------------------------------------------------------------------------------------------------------------- 2. Write a program that repeatedly prompts the user for integer values from...

  • I need help with the following assignment: Write an application named DailyTemps that continuously prompts a...

    I need help with the following assignment: Write an application named DailyTemps that continuously prompts a user for a series of daily high temperatures until the user enters a sentinel value of 999. Valid temperatures range from -20 through 130 Fahrenheit. When the user enters a valid temperature, add it to a total; when the user enters an invalid temperature, display the error message: Valid temperatures range from -20 to 130. Please reenter temperature. Before the program ends, display the...

  • Create a DataEntryException class whose getMessage() method returns information about invalid integer data. Write a program...

    Create a DataEntryException class whose getMessage() method returns information about invalid integer data. Write a program named GetIDAndAge that continually prompts the user for an ID number and an age until a terminal 0 is entered for both. If the ID and age are both valid, display the message ID and Age OK. Throw a DataEntryException if the ID is not in the range of valid ID numbers (0 through 999), or if the age is not in the range...

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
ADVERTISEMENT