+ 3

Help! Time limit exceeded while generating random number.

Well, I used srand and time to seed the number of an array the server seems to run out of time. How can I fix it?

5th Feb 2018, 11:03 AM
Akib
Akib - avatar
13 Réponses
+ 4
Your continue skips the rest of the code and play never changes so infinite loop. move your srand line out of the loop or you will always get the same dice roll.
5th Feb 2018, 12:00 PM
John Wells
John Wells - avatar
+ 4
Unless your array is huge, your code has a bug. Either post a link to it so we can help or start looking for a loop that never exits.
5th Feb 2018, 11:57 AM
John Wells
John Wells - avatar
+ 4
I'd move input into loop and add exit command to leave loop. Then, you could get multiple dice rolls.
5th Feb 2018, 12:12 PM
John Wells
John Wells - avatar
+ 4
Run it at least three times. 1) Just hit submit without giving data. 2) Put a couple p lines no e. p p 3) Put a couple p's with e. p p e
5th Feb 2018, 12:32 PM
John Wells
John Wells - avatar
+ 4
Put the guessing part in a function called only if you played. If I don't play, your higher/lower/similar won't make sense because there isn't anything to compare against. Instead of saying similar, use same or identical. Similar implies it can be a different value as long as it matches some pattern that the previous value met. For example, sum1%6 == sum%6 would be one method of doing similar.
5th Feb 2018, 1:24 PM
John Wells
John Wells - avatar
+ 3
For playground enter: p p p e at prompt to run. Default play to '?' before each read so if you run out of inputs you error and exit.
5th Feb 2018, 12:15 PM
John Wells
John Wells - avatar
5th Feb 2018, 12:28 PM
John Wells
John Wells - avatar
+ 2
https://code.sololearn.com/coJX9k92O07H/?ref=app
5th Feb 2018, 11:57 AM
Akib
Akib - avatar
+ 2
didn't exit the while loop
5th Feb 2018, 11:58 AM
Akib
Akib - avatar
+ 2
Thanks a lot. Its working. Forgot about what continue does😂😂😅😅.
5th Feb 2018, 12:09 PM
Akib
Akib - avatar
+ 1
Lol.. I just asked you that question😂😂
5th Feb 2018, 12:13 PM
Akib
Akib - avatar
+ 1
@mr.john the game is complete wanna check it out? Here is the link: https://code.sololearn.com/coJX9k92O07H/#c Tell me what you think and i will try to fix it in the next update LOL! Gonna post it soon.
5th Feb 2018, 1:04 PM
Akib
Akib - avatar
0
Where is the code?
5th Feb 2018, 11:48 AM
Ravi Chandra Enaganti
Ravi Chandra Enaganti - avatar