#issue with delays
36 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
#include <iostream>
#include <random>
#include <chrono>
#include <thread>
#include <windows.h>
#include <mmsystem.h>
#include <string>
using namespace std;
using namespace std::chrono_literals;
using namespace std::chrono;
using namespace std::this_thread;
//setting up
char test1;
//date
int p = 1;
int dmy = 1;
int day = 1;
int month = 7;
int year = 1908;
void timerr()
{
while( year > 0 )
{
sleep_for(seconds(p));
++day;
if( day == 31 && month == 1 ) //jan
{
++month;
day = 0;
}
else if( day == 29 && month == 2 && year == 1908 || year == 1912 ) //feb, leapy
{
++month;
day = 0;
}
else if( day == 28 && month == 2 && year != 1908 || year != 1912 ) //feb, reg
{
++month;
day = 0;
}
else if( day == 31 && month == 3 ) //mar
{
++month;
day = 0;
}
else if( day == 30 && month == 4 ) //apr
{
++month;
day = 0;
}
else if( day == 31 && month == 5 ) //may
{
++month;
day = 0;
}
else if( day == 30 && month == 6 ) //jun
{
++month;
day = 0;
}
else if( day == 31 && month == 7 ) //jul
{
++month;
day = 0;
}
else if( day == 31 && month == 8 ) //aug
{
++month;
day = 0;
}
else if( day == 30 && month == 9 ) //sep
{
++month;
day = 0;
}
else if( day == 31 && month == 10 ) //oct
{
++month;
day = 0;
}
else if( day == 30 && month == 11 ) //nov
{
++month;
day = 0;
}
else //dec
{
month = 12;
day = 0;
++year;
}
}
}
int main()
{
timerr();
sleep_for(seconds(p));
cout << "pause working";
cin >> test1;
}```
the issue is that for year to have a negative value (which only then will make it exit your loop), you'd have to wait literal years
endless loop? ```c++
int year = 1908;
void timerr()
{
while( year > 0 )
not exactly endless but for all practical purposes it might as well be
also that if cascade is not doing what you think it is
right now you're executing the single else block at the end every time you run around the loop
if it were working as intended however, the amount of time you'd have to wait before seeing any output would score in the hundreds of years lol
I just ran the numbers in fact
with your current faulty if cascade, which makes your program quicker than it really should, it would take an approximate 68 years before you see any output at all
that's the time it takes to increment year by one every second until it overflows to negative values
numeric_limits<int>::max() + 1
if your if cascade was working as intended, it would take about 365 seconds, give or take, before year is incremented by one
then we're looking at a mere 24855 years before you see any output
this much time ago we were still a species of cavemen and would still be for more than 15000 years onwards
that's also just about the earth's axial precession period
have you let it run for over 10 seconds using that condition?
yes
have you saved the file and compiled it before you ran it again?
(stupid question but I'm very serious)
(you have no idea how many beginners forget to save their changes and then compile the file again)
yeah I just did that
sure, use anything you like
huh, weird, it runs if I comment out the timerr function
so there must be an error in that function
well of course it does, what you're witnessing otherwise is that this function never returns because of faulty logic which I pointed out earlier