Variables across files

Hey so I have another problem. As part of my game both the enemy and player roll dexterity at the start. This dexterity is later used to make a roll number. The problem is, I only ever get 0.

cout << "The enemy got " << enemyStartRoll << " and you got " << playerStartRoll << "!" << endl;

That is where I get a zero and this is where I roll the players start number:

1
2
3
4
5
6
7
8
9
10
11
12
int startingPlayerRoll()
{

	cout << endl;
	cout << playerDexterity << endl;
		srand(GetTickCount());
				int rangePlayerRoll=(playerDexterity-1)+1; 
				for(int index=0; index<1; index++){ 
				playerStartRoll = 1+int(rangePlayerRoll*rand()/(RAND_MAX + 1.0)); 
				}
	return playerStartRoll;
}


Note: these are both codes from different .cpp files but I've used extern with some of the variables to get them across classes. I have included the header too if anyone asks.
Nevermind, I'm constantly an idiot. I forgot to even call the function to generate the enemies dexterity at any point and I also forgot to call the functions to generate the starting roll numbers too. It's early so I guess I'm tired.
Be careful when doing rangePlayerRoll*rand() that it don't cause an overflow. To be safe you should cast one of the operands to double or do the division before multiplication.
playerStartRoll = 1+int(rangePlayerRoll*(rand()/(RAND_MAX + 1.0)));
Ahh okay, thanks for that!
Topic archived. No new replies allowed.