# Random Numbers

I am writing a program in microsoft visual c++ 6.0 which requires a random number generator.  I tried using the funtion rand() but I get a error that say's function rand() does not take one parameter.
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
The function prototype of rand is

int rand( void );

Example (from Microsoft Visual C++ documentation)

/* RAND.C: This program seeds the random-number generator
* with the time, then displays 10 random integers.
*/

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

void main( void )
{
int i;

/* Seed the random-number generator with current time so that
* the numbers will be different every time we run.
*/
srand( (unsigned)time( NULL ) );

/* Display 10 numbers. */
for( i = 0;   i < 10;i++ )
printf( "  %6d\n", rand() );
}
0
Commented:
What did you try to achieve by passin ga parameter to rand() ?
0
Author Commented:
Still cannot get the program to run!!!!
0
Commented:
Post the code you have.
0
Commented:
You may need following functions, use them according to their interrelationship.

srand();      Initiate.
rand();       Value.

randomize();  Initiate.
random();     value.
0
Author Commented:
This is the code that requires a random number.  What I need to do is to assign a random number for the enemy generator, and then use the if statement to determine whether an enemy appears.

#include <stdlib.h>
#include <stdafx.h>
#include <stdio.h>
#include <iostream.h>
#include <math.h>
#include <time.h>

void main()
{

int hit_points;
int armor;
int power_level;
int expirence_level;
double enemy;
double enemy_generator;
int count;

for(;;)
{

if (enemy_generator <= 50)
{

cout << "Your encountered an enemy!!!" << endl;
}
else
{

cout << "No enemies in site" << endl;

}
}

}
0
Commented:
What's your problem? What errors have you got?

0
Commented:
srand( (unsigned)time( NULL ) );
for(;;){
enemy_generator = rand()%100;
if (enemy_generator <= 50)
{

cout << "Your encountered an enemy!!!" << endl;
}
else
{

cout << "No enemies in site" << endl;

}
}

}
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
What was wrong in my answer?
I suggested you right functions.
0
Commented: