I want to add delay of 3 seconds and its not working.
I am using DEV C++ compiler
Look at this code and please tell me what's wrong
(its saying Sleep was not decalred in this scope)
I am trying to make a program that will shoot every time I press a random key on the keyboard and if I will press the "R" key it will say reloading magazine and after 3 - 5 seconds it will react again
If you're using Windows then you can use WinApi's Sleep function (Sleep and not sleep, it's case sensitive) so for that you must include #include <Windows.h>
Otherwise you will have to rely on some dependency like chrono for a cross-platform way to pause the program, which you should probably do instead.
edit: I don't know why I said dependency.. chrono is part of the standard library..
Since "Sleep()" is a Windows function that not everyone can use I use this most often:
std::this_thread::sleep_for(std::chrono::seconds(3)); // <--- Needs header files chrono" and "thread".
And you can change "seconds" to "milliseconds" for those in between times. Just remember that 1 second = 100 milliseconds. This should work better for anything that is not Windows based.
sleep stops the program (or more precisely, the current thread, which may be the only thread you have). if you want to be able to do other stuff, just not shoot, you need to just check the time until 3 sec have passed in your game loop ... looks like this in pseudo code