Jump to content
  • Advertisement
Sign in to follow this  

2 noob questions

This topic is 4448 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

just doing a text game right now and wondering how to clear the screen completely and also how to have a random number generated. Thanks.

Share this post

Link to post
Share on other sites

Assuming c/c++, there is no standard way of clearing the screen.

You could choose to use someting like system("cls") in windows and system("clear") in unix...

There are probably ways of doing thisin code to rather than using another program.

For random numbers, you would want rand().

you need to use srand( seed ) to change the seed which will dictate the sequence you are going to get. You can use the time function with NULL as a paramenter to get a suitable "random" seed.

Here is a sample:

int main()
srand( time(NULL) )
int r1 = rand(); // could return any value.
int r2 = rand() % 10; // 0...9
int r3 = ( rand() % 21 + 10 ); // 10...30

I can' t remember the headers exaclty, I think its:

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

for c++ and:

#include <stdlib.h>
#include <time.h>

for c.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!