Game

I just started making this game, I looked up how to make the program pause for a certain amount of time. It isn't working for me, can you please help?

Here is the code:

#include <iostream>
#include <cstdlib>
using namespace std;

string firstName;
int loop = 1;

void intro()
{
cout << "What is your name?" << endl;
cin >> firstName;
sleep(2000);
cout << "Hi " << firstName << " Your going to have an amazing adventure!" << endl;
}
Assuming you are using windows, you need the header:
 
#include <windows.h> 

and Sleep(2000); begins with an uppercase letter S.
Otherwise, there is also the usleep function (nanoseconds rather than milliseconds) for POSIX (e.g. Linux), or the sleep function (takes seconds rather than milliseconds):
1
2
3
4
#include <unistd.h>
// ...
usleep(2000000); // sleep 2 seconds
sleep(2);        // sleep 2 seconds 


EDIT:
Also, just warning you, text-based games are surprisingly hard, often harder than using a graphics library. See this article: http://www.cplusplus.com/articles/G13hAqkS/
Last edited on
Topic archived. No new replies allowed.