Question Receiving no console output but no errors

Acadi

New member
Joined
Jul 3, 2022
Messages
2
Programming Experience
Beginner
Console application made to calculate time but scaled faster. I don't see any errors in Visual Studio, yet I don't recieve any console output. Could someone explain what's causing this to happen?

C#:
for (int a = 0; a < 1; a--)
{
    int day = 0;
    int year = 2875;
    int month = 0;

    if (day > 30)
    {
        day = 0;
        if (month > 12)
        {
            year++;
            month = 0;
        }
    }
    else
    {
            day++;
            System.Threading.Thread.Sleep(840000);
    }
    Console.WriteLine(day);
}
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
4,554
Location
Sydney, Australia
Programming Experience
10+
That code looks rather suspect because I see you incrementing day and year but not month. If you want to increment dates by days then you should create a DateTime value (or DateOnly these days) and call AddDays. That will give you the correct number of days for each month, including leap years.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
4,554
Location
Sydney, Australia
Programming Experience
10+
Also, it's considered good form to provide your solution if you find it yourself, so that it might help others with a similar problem. We may also be able to improve on your solution, if we know what it is. Finally, please mark your thread Resolved if the issue is resolved and mark the appropriate post as the answer, even if it's your own.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,469
Location
Chesapeake, VA
Programming Experience
10+
On a closer look, the OP's problem looks to be because of line 19. 8400000 milliseconds is 14 minutes. I suspect the user didn't wait long enough to exit the for loop and get to the console output.
 
Top Bottom