|
-
May 17th, 2005, 04:34 PM
#1
Thread Starter
Admodistrator
Timer thing..
Well actually a few things here, in vb we have a timer control that will let you run something every minute(although its very innacurate, its good for most things)...in C++, i know we have loops and stuff, but i was wondering, is there a way to stop code for say a minute?
also, can anyone give me some very basic ideas for program?
one last one, how do i get a random integer?
-
May 17th, 2005, 04:40 PM
#2
Not NoteMe
Re: Timer thing..
For a random integer lookup the use of the rand() function.
How about a number guessing game. The computer picks a random number between a set range, then the user has to guess what number it is. If incorrect they're told whether it's higher or lower.
You can use the Sleep command to set the thread (program) to idle for a number of milliseconds.
Not sure if this should be recommended though, i'm guessing it's a windows API call, thus making your coded non-portable. I expect CornedBee or someone'll have something to say.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
May 17th, 2005, 05:51 PM
#3
Thread Starter
Admodistrator
Re: Timer thing..
cool!!sounds like a neat starter game..im sure i can do it..
be back with questions, thanks for all your help so far!+5 pts
edit**
found rand, but each time it generates only one number?
Last edited by |2eM!x; May 17th, 2005 at 06:05 PM.
-
May 17th, 2005, 06:14 PM
#4
Not NoteMe
Re: Timer thing..
If i remember correctly you need to 'seed' the random number. The rand function isn't truly random, it produces a seemingly random list of numbers, given a starting point (the seed).
Search this forum for 'random number seed' and you'll probably get a function name and explanation easily enough.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
May 17th, 2005, 06:38 PM
#5
Thread Starter
Admodistrator
Re: Timer thing..
eh...nothing seems to be working here...
VB Code:
#include <iostream>
#include <time.h>
#include <stdlib.h>
using namespace std;
int main ()
{
int randomNumber;
srand;
randomNumber = rand % (11-1) + 1;
cout << randomNumber;
system( "pause" );
return 0;
}
i get:
C:\Program Files\Microsoft Visual Studio\VC98\Projects\Cpp1.cpp(11) : warning C4551: function call missing argument list
C:\Program Files\Microsoft Visual Studio\VC98\Projects\Cpp1.cpp(12) : error C2296: '%' : illegal, left operand has type 'int (__cdecl *)(void)'
-
May 18th, 2005, 02:22 AM
#6
Re: Timer thing..
In C++, unlike VB, you always need function call parentheses:
srand();
Oh, and srand expects a value that you need to pass, so:
srand(time(NULL));
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 18th, 2005, 03:34 PM
#7
Thread Starter
Admodistrator
Re: Timer thing..
yessir, i figured it out.thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|