Sign in to follow this  

2 noob questions

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this