Hello all, I get the feeling I'm doing something really simple wrong here, personally, I think its a matter of scope, but I cant seem to find the problem if it is, anyway, heres my code, and im hopeing someone will take the time to peruse it real quik for me. In this block of code, the integer variable 'killer' causes a run time error and crashes the program. If someone want the entirety of the code, as I have left out most of the extemporaneous crap code that doesnt relate to this problem, let me know and i'll post it. Anyway, Im at my wits end......thank you for your time.
************************************************** **
-#includes and stuff up here-
int randMon(int location) {
int beastPos[9] = {0};
switch(location) {
case 0:
beastPos[0] = 0;
beastPos[1] = 0;
beastPos[2] = 0;
beastPos[3] = 0;
beastPos[4] = 0;
beastPos[5] = 0;
beastPos[6] = 0;
beastPos[7] = 1;
beastPos[8] = 1;
beastPos[9] = 1;
break;
case 1:
beastPos[0] = 0;
beastPos[1] = 0;
beastPos[2] = 0;
beastPos[3] = 0;
beastPos[4] = 0;
beastPos[5] = 1;
beastPos[6] = 1;
beastPos[7] = 1;
beastPos[8] = 1;
beastPos[9] = 1;
break;
case 2:
beastPos[0] = 3;
beastPos[1] = 3;
beastPos[2] = 3;
beastPos[3] = 3;
beastPos[4] = 3;
beastPos[5] = 6;
beastPos[6] = 6;
beastPos[7] = 6;
beastPos[8] = 6;
beastPos[9] = 6;
break;
case 3:
beastPos[0] = 9;
beastPos[1] = 9;
beastPos[2] = 9;
beastPos[3] = 9;
beastPos[4] = 9;
beastPos[5] = 9;
beastPos[6] = 3;
beastPos[7] = 3;
beastPos[8] = 6;
beastPos[9] = 6;
break;
};
int fightMe = beastPos[(rand() % 10)];
return fightMe;
};
int main() {
srand(time(0));
int anumber = (rand() % 4);
int killer = randMon(anumber);
return 0;
}
************************************************** **
help!!!! =)