Sign in to follow this  

2 noob questions

This topic is 4260 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

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.

Share this post


Link to post
Share on other sites

This topic is 4260 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.

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