Name: Anonymous 2007-06-07 12:06 ID:+O+EKF2S
Hey guys this compiles but when i build the selected number of knights only the first one gets a random number and the rest get -801208102 or something?
// knight values is a struct.
knightValues* CreateKnights2(int& numberOfKnights2)
{
system("CLS");
srand( (unsigned)time( NULL ) );
numberOfKnights2 = 0;
std::cout << "Enter how many Knights you would like to create: ";
std::cin >> numberOfKnights2;
knightValues* myCreatedKnights2 = new knightValues[numberOfKnights2];
for (int i = 0; i < numberOfKnights2; i++){
myCreatedKnights2[i].health = rand() % 100 + 100;
myCreatedKnights2[i].armour = rand() % 200 + 150;
return myCreatedKnights2; // this is being assigned to army in the switch
}
}
------
knightValues* army; // army is the pointer to the array of knights
int nKnights; // this is the number of knights
------
switch (option)
{
case 1 : army = CreateKnights(nKnights); break;
// knight values is a struct.
knightValues* CreateKnights2(int& numberOfKnights2)
{
system("CLS");
srand( (unsigned)time( NULL ) );
numberOfKnights2 = 0;
std::cout << "Enter how many Knights you would like to create: ";
std::cin >> numberOfKnights2;
knightValues* myCreatedKnights2 = new knightValues[numberOfKnights2];
for (int i = 0; i < numberOfKnights2; i++){
myCreatedKnights2[i].health = rand() % 100 + 100;
myCreatedKnights2[i].armour = rand() % 200 + 150;
return myCreatedKnights2; // this is being assigned to army in the switch
}
}
------
knightValues* army; // army is the pointer to the array of knights
int nKnights; // this is the number of knights
------
switch (option)
{
case 1 : army = CreateKnights(nKnights); break;