CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2012
    Posts
    11

    [RESOLVED] Creating a random number generator program help

    I'm trying to create a program that creates random numbers. I looked through some examples and this is what I came up with. The time identifier seems to be undefined yet I see no reason it is undefined. please help!

    Code:
    #include "stdafx.h"
    #include <iostream>
    using namespace std;
    int main()
    {
    	//Re-seed the random-number generator
    	time_t now;
    	time(&now);
    	srand(now);
    	rand();
    	//Print out a list of random numbers
    	for (int i=0;i<5;i++)
    	{
    		cout << rand() % 100 << endl;
    	}
    	system("pause");
    		return 0;
    }
    here's my error code..

    1>------ Build started: Project: bake, Configuration: Debug Win32 ------
    1> bake.cpp
    1>c:\users\jonbecher\documents\visual studio 2012\projects\bake\bake\bake.cpp(8): error C3861: 'time': identifier not found
    1>c:\users\jonbecher\documents\visual studio 2012\projects\bake\bake\bake.cpp(9): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

  2. #2
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Creating a random number generator program help

    Maybe you should include time.h?
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  3. #3
    Join Date
    Jun 2012
    Posts
    11

    Re: Creating a random number generator program help

    oh DUH haha, thank you so much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured