I am having a problem displaying random numbers, I'm trying to make a dice game where you play against the computer and the first one to 100 wins. However, my random number is never random, it always comes out as the same number.
From what I understand to simply display a random number in the console is,
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int i;
i = rand();
cout << i;
return 0;
}
The problem is that I ALWAYS get the number 41 from this program, no matter how many times i run it.
I've changed it to work like a die;
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int i;
i = (rand()%6)+1;
cout << i;
return 0;
}
And from that, I always get the number 6. Basically its not coming out as a random number and I can't figure out why. Can anyone tell me what I'm doing wrong?