Answer to Question #284393 in C# for Kim

Question #284393

Create a program that will compute and display the number of days based on the

input starting and ending year.

Sample output:

Enter the starting year: 1999

Enter the ending year: 2001

No. of year/s: 3

No. of days: 1096

Thanks for answering this!


1
Expert's answer
2022-01-03T10:46:59-0500
using System;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter the starting year: ");
            var startingYear = int.Parse(Console.ReadLine());
            Console.Write("Enter the ending year: ");
            var endingYear = int.Parse(Console.ReadLine());
            Console.WriteLine("No. of year/s: {0}", CountYears(startingYear, endingYear));
            Console.WriteLine("No. of days: {0}", CountDays(startingYear, endingYear));
        }

        static int CountYears(int startingYear, int endingYear) => endingYear - startingYear + 1;

        static long CountDays(int startingYear, int endingYear)
        {
            var daysCount = 0L;
            for (var currentYear = startingYear; currentYear <= endingYear; currentYear++)
                daysCount += DateTime.IsLeapYear(currentYear) ? 366 : 365;
            return daysCount;
        }
    }
}

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