Updating an integer according to time?

This is a discussion on Updating an integer according to time? within the C++ Programming forums, part of the General Programming Boards category; Is there a command to update an int according to the time using a command? Say i have somthing like: ...

  1. #1
    Unregistered
    Guest

    Question Updating an integer according to time?

    Is there a command to update an int according to the time using a command? Say i have somthing like:

    srand(time(NULL));

    int x=rand() % 15;

    cout<<x;
    //command here?
    cout<<x;

    Where that second x is I need it to be different than the first one, but using the same int. Is this possible?

  2. #2
    A Banana Yoshi's Avatar
    Join Date
    Oct 2001
    Posts
    859
    try random(time);
    Yoshi

  3. #3
    Unregistered
    Guest

    Unhappy

    Didnt work.

    I forgot to add that I am using Windows 2000 and MSVC++.

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    194
    Do you simply want another random number for x?
    You only need to call srand() once at the start of the main
    Code:
    x = rand() % 15;
    would give you a new random number, but using the same random seed as before

  5. #5
    Unregistered
    Guest
    Hmmm...didnt do what I wanted it to do. Let me try to explain what I want in a better way.

    What I'm doing is that I'm making a little RPG battle system. Since you dont know how many times you are going to hit the enemy, you don't know how many times you have to make another int for that attack. So what I'm wondering is, is there a way to keep updating an int while in the program?

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    just use a while loop.

    while(monster != DEAD && character != DEAD)
    {
    get random number;
    act on it accordingly;
    if someone dies set their status to DEAD (enum works well for this);
    } // loop ends when 1 thing dies
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  7. #7
    Unregistered
    Guest
    Awesome, thanks it worked

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Journey time prog 1 minute wrong
    By mike_g in forum C Programming
    Replies: 4
    Last Post: 10-12-2006, 04:41 AM
  2. What is the best way to record a process execution time?
    By hanash in forum Linux Programming
    Replies: 7
    Last Post: 03-15-2006, 07:17 AM
  3. Killing someones grandparents
    By nickname_changed in forum A Brief History of Cprogramming.com
    Replies: 37
    Last Post: 09-07-2003, 08:56 AM
  4. The Timing is incorret
    By Drew in forum C++ Programming
    Replies: 5
    Last Post: 08-28-2003, 05:57 PM
  5. convert integer unix timestamp to time
    By rotis23 in forum C Programming
    Replies: 2
    Last Post: 11-18-2002, 09:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21