Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ Help, Array error

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;

Name: Anonymous 2007-06-07 21:06 ID:+O+EKF2S

May i ask why no one understands why i have to make this a certain way, i can't just go adding john doe. It needs to meet the requirements for the task.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List