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?
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.

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
loonstyleAuthor Commented:
Still cannot get the program to run!!!!
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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
ozoCommented:
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

Your issues matter to us.

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

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.