random(), randomize()

shoover1

Baseband Member
Messages
22
Hi.

Are these functions just dead? They work in Visual C++ 6.0 but not in Visual Studio 2008. If so what header works properly so I can program at home using Visual Studio 2008 and bring it into school where we use C++ 6.0

Please, please DONT MENTION I HAVE TO USE CSTDLBIEWFWO AND RAND() ETC... THAT WON'T HELP. JUST PLEASE ANSWER MY QUESTION.
 
Wait, did you use time.h? You need that and use rand(). I know you said not to say that, but that's how it is. If you want another way, google it.
 
the command srand(Time.NULL) takes place of randomize.

oh, and joga, I've always seen it used as time.h not ctime.h maybe changing time.h (if that's what he's using) to ctime will fix it.
 
Okay thanks guys for your help. Can you tell me the parameters for rand(), such as declaring minimum and maximum integers randomly being picked?
 
Code:
/* rand example: guess the number */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main ()
{
  int iSecret, iGuess;

  /* initialize random seed: */
  srand ( time(NULL) );

  /* generate secret number: */
  iSecret = rand() % 10 + 1;

  do {
    printf ("Guess the number (1 to 10): ");
    scanf ("%d",&iGuess);
    if (iSecret<iGuess) puts ("The secret number is lower");
    else if (iSecret>iGuess) puts ("The secret number is higher");
  } while (iSecret!=iGuess);

  puts ("Congratulations!");
  return 0;
}

Credit to: CPlusPlus.com (Click on link for more information)
 
warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data

on the srand ( time(NULL) ); statement
 
Well I got like 8 other random conversions in my program so ill get back to you on the results. Thanks for your help!
 
No problem man. I never use random conversions. I had to for my semester final. So I just made a number guessing game which was really boring. If you want to see the code for that I can send you the file.
 
Back
Top Bottom