How to store random number in int?

I'm trying to make a program that says something random every time you press enter. I can't figure out how to store a random number into a variable. How woudl I go about doing that?
int rNumber = rand();
That was almost too easy, so either you haven't heard of the rand() (in that case you need to initialize it by calling srand() first) function yet or I misunderstood your question.
I think he meant that yes. If you have a maximum wanted value, just modulo it with that, like:

int rNumber = rand() % 100;

I've heard of rand(), but I've only learned to print rand by typing
1
2
srand(time(0))
cout << 1+(rand()%6) << endl;

to simulate a dice roll.
Last edited on
rand is a simple function with a simlpe return value as any other function. just assign it to and int and u win.
Topic archived. No new replies allowed.