2 noob questions

Started by
1 comment, last by petelta 18 years ago
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.
Advertisement
Language?

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.
thanks alot. sorry i forgot to say Im using C++. that info will help.

This topic is closed to new replies.

Advertisement