Thread: help with random number generator

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    84

    help with random number generator

    for a uni assignment i have downloaded an example of a random number generator, and it dosen't work. it worked when it was demonstrated in the lecture but now it does not.

    here is the code that i compiled aand got the errors from. i'm using microsoft visual studio 6 on wondows xp.

    #include <cstdlib>
    #include <ctime>
    #include <iostream>

    using namespace std;

    int main(void)
    {
    int dice[10];
    int seed =(int)(time(0));
    srand(seed);

    for(int i = 0; i < 10; i++)
    {


    dice[i] = (rand() % 6) + 1;

    }

    for(int x = 0; x < 10; x++)
    {
    cout << dice[x] << " : ";
    }

    cout << endl;

    return 0;

    }

    the errors are all in the time.h header file.

    :\program files\microsoft visual studio\vc98\include\time.h(36) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
    c:\program files\microsoft visual studio\vc98\include\time.h(208) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
    c:\program files\microsoft visual studio\vc98\include\time.h(209) : error C2143: syntax error : missing ';' before '}'
    c:\program files\microsoft visual studio\vc98\include\time.h(209) : error C2143: syntax error : missing ';' before '}'
    c:\program files\microsoft visual studio\vc98\include\time.h(209) : error C2143: syntax error : missing ';' before '}'
    c:\program files\microsoft visual studio\vc98\include\errno.h(29) : error C2143: syntax error : missing ';' before '{'
    c:\program files\microsoft visual studio\vc98\include\errno.h(29) : error C2447: missing function header (old-style formal list?)
    Error executing cl.exe.

    those are the error messages i get, anybody help?

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    xp and vc++ 6 and it compiles fine

  3. #3
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    It would appear that Microsoft hates you. Take your computer and smash it against a large glass window, preferably tinted.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    84
    i won't smah it against a wall, it cost too much to upgrade. instead i will cry.

    i will have to try it on the uni computers to see if it will work.

  5. #5
    Registered User
    Join Date
    Jan 2003
    Posts
    118
    Works fine for me, I am using Visual studio .NET on Windows XP.
    Try reinstalling your'e compiler.
    Why drink and drive when you can smoke and fly?

  6. #6
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Definitely sounds like a problem with your compiler.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue w/ Guess My Number Program
    By mkylman in forum C++ Programming
    Replies: 5
    Last Post: 08-23-2007, 01:31 AM
  2. Good Random Number Generator
    By MethodMan in forum C Programming
    Replies: 4
    Last Post: 11-18-2004, 06:38 AM
  3. How do I restart a random number sequence.
    By jeffski in forum C Programming
    Replies: 6
    Last Post: 05-29-2003, 02:40 PM
  4. how to link random number generator with cpu?
    By chris285 in forum C++ Programming
    Replies: 5
    Last Post: 04-28-2003, 05:26 AM
  5. Seeding Random Number Generator
    By zdude in forum C++ Programming
    Replies: 2
    Last Post: 09-05-2002, 03:10 PM