- #1
VirObitus
- 19
- 0
Hi again,
I *think* I am having a problem with break, as I can't figure out why I am having the problem I am having. This code is meant to compare 24 integer 'traits' against 48 minimum and maximum values, and if all 24 fit within their respective min and max value, to exit the loop. If the response (saythis) fails even one of the min/max tests, it should pick a new saythis. Right now it does the same thing every time - throws out exactly 1 saythis, and chooses the second one.
I've also been told to avoid using break, as it is bad coding style (or something), so if there is another way to accomplish this, I would love to see it.
I *think* I am having a problem with break, as I can't figure out why I am having the problem I am having. This code is meant to compare 24 integer 'traits' against 48 minimum and maximum values, and if all 24 fit within their respective min and max value, to exit the loop. If the response (saythis) fails even one of the min/max tests, it should pick a new saythis. Right now it does the same thing every time - throws out exactly 1 saythis, and chooses the second one.
I've also been told to avoid using break, as it is bad coding style (or something), so if there is another way to accomplish this, I would love to see it.
Code:
int success = -1;
int traitCount = 24;
int ResponseCount = 120;
int TraitMatrix[120][24]; // if this array were graphed, all the odd numbers would be min, and all the even ones would be max
int a = 0;
int b = 1;
while (success < 1)
{
saythis = rand()%responseCount; //creates a random number between 0 and responseCount and assigns it to saythis
printf("first saythis is: %d\n\n", saythis); //debug - see each random number as it is selected
for (i = 0; i < traitCount; i++);
{
if (success == 0)
{
break;
}
testMin = traitMatrix[saythis][a]; //sets the minimum possible value of the trait
testMax = traitMatrix[saythis][b]; //sets the maximum possible value of the trait
if (traits[i] >= testMin && traits[i] <= testMax) //tests the NPC's actual trait against the min and max value
{
a = a+2;
b = b+2;
success = 1;
}
else
{
success = 0;
}
}
}
Last edited: