Answer to Question #284394 in C# for Kim

Question #284394

Create a program that will ask the user to enter five (5) years (in no particular order)

and check whether each year is a leap year or not. Moreover, your program should display:

"More leap years," if there is a greater number of leap years, otherwise display "Fewer leap years."

Thanks for answering this!


1
Expert's answer
2022-01-03T16:20:42-0500
using System;


namespace IsLeapYear
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            /*
             Create a program that will ask the user to enter five (5) years (in no particular order)
             and check whether each year is a leap year or not. Moreover, your program should display:
             "More leap years," if there is a greater number of leap years, otherwise display "Fewer leap years."
             */
            Console.WriteLine("Please, enter five (5) years in no particular order: ");
            int[] years = new int[5];
            byte lyp = 0;
            byte isntlyp = 0;
            for (int i = 0; i < years.Length; i++)
            {
                years[i] = int.Parse(Console.ReadLine());
               
            }


            for (int i = 0; i < years.Length; i++)
            {
                if (DateTime.IsLeapYear(years[i]))
                {
                    Console.WriteLine($"{years[i]} - Leap year!");
                    lyp++;
                }
                else
                {
                    Console.WriteLine($"{years[i]} - Is not leap year!");
                    isntlyp++;
                }
            }
            if(lyp > isntlyp)
                Console.WriteLine("More leap years!");
            else if(isntlyp > lyp)
                Console.WriteLine("Fewer leap years!");
            else
                Console.WriteLine("Leap years and common years are equal!");
            Console.ReadLine();
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS