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;
}
Printable View
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;
}
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;
}
that code dosent compile
that helps :rolleyes: how about some errors?
edit: the 'c' is lowercase in clock()
srand(Clock()); there is a problem there it sais "warning in function int"
'clock undeclared'
(each underclared
check my last post
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.Quote:
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:p
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().
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]---
:( 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;
}