using System;
using System.Globalization;
namespace _13._Holidays_Between_Two_Dates
{
class Program
{
static void Main(string[] args)
{
var startDate = DateTime.ParseExact(
Console.ReadLine(), "d.m.yyyy", CultureInfo.InvariantCulture);
var endDate = DateTime.ParseExact(
Console.ReadLine(), "d.m.yyyy", CultureInfo.InvariantCulture);
var holidaysCount = 0;
// Problem: infinite loop
for (var date = startDate; date <= endDate; date.AddDays(1))
{
if (date.DayOfWeek == DayOfWeek.Saturday ||
date.DayOfWeek == DayOfWeek.Sunday)
{
holidaysCount++;
}
}
Console.WriteLine(holidaysCount);
}
}
}
I am having troubles finding why iIcan't assign a value to the var date in the loop. Therefore the loop goes infinite. N00b