Resolved Receiving no console output but no errors

Acadi

New member
Joined
Jul 3, 2022
Messages
3
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);
}
 
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.
 
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.
 
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.
 
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.
Yeah, realized this issue and made a few changes to the program after I'd examined the code closer.
 
Actually the whole program should probably be something like:

C#:
var d = new DateTime(2875,1,1);
while(true)
{
    d=d.AddDays(1);
    System.Threading.Thread.Sleep(1000);
    Console.WriteLine(d.Day);
}
 
Unfortunately, these two are not equivalent:
C#:
while (true)
{
    :
}

and

C#:
for (int a = 0; a < 1; a--)
{
    :
}

The former will loop infinitely. The latter will break when the repeated integer subtraction makes the integer value roll over into a positive number.
 
Actually, only a little over 68 years.
 
Think you might have looked at the wrong code block; OP's code runs 2.15 billion iterations of 840 seconds, which is about 57k years (but even keeping an app running for 68 years would be quite an achievement.. :D )
 
Last edited:
Ah! You are correct. I thought the code has changed to just pause for 1 second.
 
Back
Top Bottom