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.  
Please help out with this problem.
loonstyleAsked:
Who is Participating?
 
ozoConnect With a Mentor 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
 
chensuCommented:
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
 
KangaRooCommented:
What did you try to achieve by passin ga parameter to rand() ?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
loonstyleAuthor Commented:
Still cannot get the program to run!!!!
0
 
snifongCommented:
Post the code you have.
0
 
sumant032199Commented:
You may need following functions, use them according to their interrelationship.

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

randomize();  Initiate.
random();     value.
0
 
loonstyleAuthor 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
 
chensuCommented:
What's your problem? What errors have you got?

Please don't reject a correct answer.
0
 
sumant032199Commented:
What was wrong in my answer?
I suggested you right functions.
0
 
ozoCommented:
And what was wrong in my answer and chensu's answer?
What was the answer to KangaRoo's question?
0
All Courses

From novice to tech pro — start learning today.