V
Vaelix
Guest
Since I have no Real Friends to ask who are intelligent thumbdown, I figured I'd ask here..
Heres the deal, basically Im trying to generate a random number, then use that to determine what "Pet" That character would get, Im also trying to make it so that it invokes an outside function [Outside of main()] to do this.
Something like this.. *Note* This is a console application (CMD) nothing too extensive. (Trying to keep it simple)
int pet()
{
srand(time(0))
int randomNumber = rand(); // I use randomNumber because i might need
int petNumber = (randomNumber % 5) + 1; // it outside of the use for petNumber.
*Ifs 1-5*
return petNumber;
}
I have 5 If conditionals, all which point to a specific console output based on which # is rolled.
(Example..)
if (pet == 1){
cout << "tiger\n";
}
if (pet == 2){
cout << "wolf\n";
}
Pretty much, if i compile the source, it will crash when i reference the pet, which I do near the end with..
Cout << pet() << endl;
In debugging mode, (Using Bloodshed Dev C++) Im getting a segmentation fault, access violation when I go to access the function. (Bear with me as Im just starting to get into this again, been busy, and not in school for it sadly).
My biggest frustration here is that, if I move the Ifs out of the pet function and into main(), the program will stop crashing, but, will no longer apply an animal to the number that is generated, instead it will roll a separate random number when my compiler gets to Cout << pet() << endl; At which time, it will simple output a number instead of hitting one of the Ifs..
(If this doesnt make any sense, and you are actually interested in helping me.. Shoot me a PM )
(Otherwise... )
Heres the deal, basically Im trying to generate a random number, then use that to determine what "Pet" That character would get, Im also trying to make it so that it invokes an outside function [Outside of main()] to do this.
Something like this.. *Note* This is a console application (CMD) nothing too extensive. (Trying to keep it simple)
int pet()
{
srand(time(0))
int randomNumber = rand(); // I use randomNumber because i might need
int petNumber = (randomNumber % 5) + 1; // it outside of the use for petNumber.
*Ifs 1-5*
return petNumber;
}
I have 5 If conditionals, all which point to a specific console output based on which # is rolled.
(Example..)
if (pet == 1){
cout << "tiger\n";
}
if (pet == 2){
cout << "wolf\n";
}
Pretty much, if i compile the source, it will crash when i reference the pet, which I do near the end with..
Cout << pet() << endl;
In debugging mode, (Using Bloodshed Dev C++) Im getting a segmentation fault, access violation when I go to access the function. (Bear with me as Im just starting to get into this again, been busy, and not in school for it sadly).
My biggest frustration here is that, if I move the Ifs out of the pet function and into main(), the program will stop crashing, but, will no longer apply an animal to the number that is generated, instead it will roll a separate random number when my compiler gets to Cout << pet() << endl; At which time, it will simple output a number instead of hitting one of the Ifs..
(If this doesnt make any sense, and you are actually interested in helping me.. Shoot me a PM )
(Otherwise... )