+ 1
Getting timeout error during snippit.
Basically tried adding time as a function.. and failed. https://code.sololearn.com/c3lHarOWKI0Q/?ref=app
8 odpowiedzi
+ 1
Thankyou for the reply. Can you explain why that is?
I initialise origtime as 0, I change the value to being = to millitime after giving it its value, then re input during recursion.
if(millitime == 0.0f)
{
millitime = time(NULL);
origtime = millitime;
}
Or Is it not possible to change variables with defined values in the argument list?
when I output the values individually. they = 1.65684e+09
+ 1
Shouldn't millitime be changing in the recursion? "Delaycomm(delay, origtime, time(NULL))"
or is that way of inputting new values for defined variables not possible in c++?
Been mostly modding a game, where I'm used to implementing it that way. I will try defining it before now though. But would still like to know
edit: after setting the value before recursion I am still facing the same problem.
am I miss understanding time(), maybe?
+ 1
May be it is because SL support issue.
There it getting same values for millitime and origtime because of "no delay" time in seconds.. Try this in PC or interactive environment.. I hope it works fine there..
+ 1
You need to maintain time delay for next call for time(0). So that you can get different values.
Try this code, Run multiple times, time difference is maximum 1s only.. So you need some time delay.. For this type of small programs, from interactive environment, you can put delay.. but in SL, I think it don't support add delay because of time limit.
#include <iostream>
using namespace std;
int main() {
time_t begin,end;
begin= time(NULL);
for(long i = 0; i < 150000000; i++)
end = time(NULL);
printf("for loop used %f seconds to complete the execution\n", difftime(end, begin));
return 0;
}
0
if(millitime-origtime < delay)
{
delaycomm(delay, origtime, time(NULL));
}
This block cause infinite function calls..
Because your origtime is initially 0
and millitime-origtime will always a negative value so always less than delay.
0
Ok. Your changing values in if block but those will have same values because
millitime = time(0) then
origtime= millitime, both will have same value and millitime-origtine= 0 which is less than delay 0<=0.02 true always next.... So cause infinite calls...
0
Well. Looks like I found the exact amount of times it's willing to re run.
Is there an instruction limit on this? Or does it have to do with memory allotment?(which I have no understanding of)
0
Thank you for the response! Will try on something like vscode.
I now understand what you meant.
Wish I could + you some more lol
.