i want to learn how to do random numbers i know that is completly wrong but how would i make a=a random number?Code:#include<iostream> using namespace std; int main() { int a; a=random; cout<<a<<endl; return 0; }
i want to learn how to do random numbers i know that is completly wrong but how would i make a=a random number?Code:#include<iostream> using namespace std; int main() { int a; a=random; cout<<a<<endl; return 0; }
Last edited by makveli; 11-11-2003 at 10:08 AM.
try searching the board (http://cboard.cprogramming.com/showt...threadid=47035), but i'll write some random int generating code...
Code:#include <iostream> #include <conio.h> #include <cstdlib> #include <ctime> int main() { srand(clock()); //to make the random number random int randInt=rand(); //a large random int std::cout<<randInt<<std::endl <<"Press any key to continue . . . "; getch(); return 0; }
Last edited by major_small; 11-11-2003 at 10:54 AM.
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
that code dosent compile
that helps how about some errors?
edit: the 'c' is lowercase in clock()
Last edited by major_small; 11-11-2003 at 10:47 AM.
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
srand(Clock()); there is a problem there it sais "warning in function int"
'clock undeclared'
(each underclared
check my last post
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
u dont have a compiler in front of u wat about behind you?
Don't be such a douche-bag when someone is trying to help you.Originally posted by makveli
u dont have a compiler in front of u wat about behind you?
lol i aint tryin to be offensive but his last post sais somethin like "dont expect us to do all the work for you, not all of us have a compiler in front of us"
and he was just tryin to get help
You greatly misinterpretted that rule...
Note: If you don't feel like including <ctime> and you have <windows.h> included, i.e. you're writing a non-console Windows app, GetTickCount() should suffice instead of clock().
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
thanx but could anyone write a simple program using random numbers and show us please
Here's what I use to do random numbers:
---***---
include <iostream.h>
include <stdlib.h>
include <time.h>
---***---Code:int main () { int num; double flt; // seed the random number generator srand (unsigned (time (NULL) ) ); // a random integer from 0 to 10 int = rand() % 11; cout << "integer, 0 to 10 --> " << int << endl; // a random float from 0 to 10 flt = rand() / double (RAND_MAX) * 10; cout << "float, 0 to 10 --> " << flt << endl; return 0; }
The function rand() simply returns an integer from 0 to a constant RAND_MAX.
---[Red Haze]---
----[Red Haze]----
its has alot of parse errors it dont work
the program i gave you is pretty much as simple as you can get, but here's something even easier (but much less random):
Code:#include <iostream> #include <cstdlib> using std::cin; using std::cout; using std::endl; int main() { srand(rand()); //to make the random number random... with a random number int randInt=rand(); //a large random int cout<<randInt<<endl <<"Press any key to continue . . . "; cin.get; return 0; }
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT