Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Visual C# exercise problems 5a and 5b nttps://ngcengage.com/static/nb/u.. Bookma

ID: 3755717 • Letter: V

Question

Visual C# exercise problems 5a and 5b

nttps://ngcengage.com/static/nb/u.. Bookmarks A Pharos Print Manage INDTAP Q Search this course ul. Cengage rm with winds of less than 7AA TS is not a hurricane. 5. a. Write a 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. b. Write a program named CheckMonth2 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. 6. Account numbers sometimes contain a check digit that is the result of a mathematical calculation. The inclusion of the digit in an account number helps ascertain whether the number is a valid one. Write an application named CheckDigit that asks a user to enter a

Explanation / Answer

5a)

using System;

public class CheckMonth

{

public static void Main()

{

int month = Convert.ToInt32(Console.ReadLine());

if(month >= 1 && month <= 12) {

Console.WriteLine("{0} is a valid month", month);

}

else {

Console.WriteLine("{0} is not a valid month", month);

}

}

}

5b)

using System;

public class CheckMonth2

{

public static void Main()

{

int[] Months = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int month = Convert.ToInt32(Console.ReadLine());

if(month >= 1 && month <= 12) {

int day = Convert.ToInt32(Console.ReadLine());

if(day >= 1 && day <= Months[month-1])

Console.WriteLine("{0} and {1} is valid", month, day);

else

Console.WriteLine("{0} is invalid", day);

}

else {

Console.WriteLine("{0} is invalid", month);

}

}

}