Thread: Program Fatal Error- Please Explain

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    51

    Program Fatal Error- Please Explain

    unresolved external symbol "short __cdecl displaygrid(short (* const)[16][5],short (* const)[16][5])" (?displaygrid@@YAFQAY1BA@4F0@Z)

    Can someone please explain that error... looks a little like gibberish to me (I'm new at programming).

    Thanks in advance.

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    show your code....

  3. #3
    julie lexx... btq's Avatar
    Join Date
    Jun 2002
    Posts
    161
    this is an error you usually get when you haven't defined the
    actuall code for the function. For instance:

    Code:
    #include <iostream.h>
    int DoSomething(); //function prototype
    
    int main()
    {
         int c = DoSomething();
         return 0;
    }
    this would cause the same error saying something like
    "unresolved symbol int DoSomething() ... " since the
    actual code for this function isn't defined.

    if you post the code maybe I could be more precise..

    /btq
    ...viewlexx - julie lexx

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    51
    Code:

    //By Tony Wong

    #include <iostream>
    #include <stdlib.h>
    #include <windows.h>
    #include <conio.h>
    #include "color.h"

    #define AZ Sleep(25);

    using namespace std;
    using namespace Color;

    //function prototypes
    short game(short siRestart); //main game function
    short random(short siLimit); //randomizing function
    short randwall(short siCompGrid[8][16][5]); //function creating random wall
    inline short difficulty(); //function prompts for difficulty
    inline void briefing();
    short displaygrid(short siPlayerGrid[8][16][5], short siCompGrid[8][16][5]); //function displaying grid
    short setter(short siPlayerGrid[8][16][5], short siCompGrid[8][16][5], short i, short j); //sets player grid sector equal to comp grid sector
    void buy(short siCompGrid[8][16][5], short siMoney[2]); //buying function
    void status(short siCompGrid[8][16][5]); //display units and money
    void clrscr(); //function which clears screen

    //global variables
    //grids
    short siCompGrid[8][16][5];
    short siPlayerGrid[8][16][5];
    //misc
    short siMoney[2];

    main ()
    {
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HA NDLE), FOREGROUND_BLUE | FOREGROUND_GREEN ); //set text color to cyan
    std::cout << "B"; AZ std::cout << "y"; AZ std::cout << ":"; AZ std::cout << " "; AZ std::cout << "T"; AZ std::cout << "h"; AZ std::cout << "e"; AZ; std::cout << " "; AZ ; std::cout << "F"; AZ ; std::cout << "o"; AZ; std::cout << "l"; AZ; std::cout << "l"; AZ; std::cout << "o"; AZ ; std::cout << "w"; AZ ; std::cout << "i"; AZ; std::cout << "n"; AZ; std::cout << "g"; AZ ; std::cout << " "; AZ; std::cout << "P"; AZ; std::cout << "e"; AZ; std::cout << "o"; AZ; std::cout << "p"; AZ; std::cout << "l"; AZ; std::cout << "e" << endl;
    std::cout << "Joe Formica" << endl;
    Sleep(250);
    std::cout << "Tony Wong" << endl;
    Sleep(250);
    std::cout << "Version 1.0 Beta" << endl << endl;
    Sleep(250);

    short siRestart = 1;

    while (siRestart == 1) //check to see if user has finished playing
    {
    siRestart = game(siRestart); //calls game function
    }

    //displays gratitude
    std::cout << "Thank you for playing WarGames 2010!" << endl;
    Sleep(1000);
    std::cout << "I hope you enjoyed it as much as I enjoyed creating it!" << endl;
    Sleep(2000);
    std::cout << "By Tony Wong" << endl << endl;

    Sleep(1000);

    return 0;
    }

    short game(short siRestart)
    {
    //grid
    short siPlayerGrid[8][16][5] = {0};
    short siCompGrid[8][16][5] = {0};
    //units
    short siPlayerUnits[20][5] = {0};
    short siCompUnits[20][5] = {0};
    //misc
    short siDifficulty = 0;
    short siWinner = 0;

    siDifficulty = difficulty();

    briefing();

    randwall(siCompGrid);

    /* memcpy((void *)siPlayerGrid, (void *)siCompGrid, sizeof(short)*8*16*5);

    for(i = 0; i < 8; i++)
    for(j = 0; j < 16; j++)
    for(k = 0; k < 5; k++)
    siPlayerGrid[i][j][k] = siCompGrid[i][j][k];
    */

    if (siDifficulty == 0)
    {
    while (siWinner == 0)
    {
    displaygrid(siPlayerGrid, siCompGrid); //display grid funcion
    buy(siCompGrid, siMoney); //buy phase
    }
    if (siWinner != 0) //check for winner
    {
    //check for winner
    }
    }
    else
    {
    while (siWinner == 0)
    {
    displaygrid(siPlayerGrid, siCompGrid); //display grid funcion
    buy(siCompGrid, siMoney); //buy phase
    }
    if (siWinner != 0) //check for winner
    {
    //check for winner
    }
    }

    //check winner, display appropriate message
    if (siWinner == 1)
    {
    std::cout << "Congratulations, you have defeated completed all mission objectives"; //display victory
    }
    else std::cout << "Your mission is a failure"; //display defeat

    do
    {
    if (siRestart != 1 && siRestart != 0)
    {
    std::cout << "Error, please enter a value of 1 or 0";
    }
    std::cout << "Play again? (1 = Yes, 0 = No): "; //ask to restart
    std::cin >> siRestart; //input answer into variable
    }
    while(siRestart != 1 && siRestart != 0); //check to make sure possible answer entered

    return siRestart; //return siRestart
    }

    short randwall(short siCompGrid[8][16][5])
    {
    //randomize variables
    short siRandVer = 0;
    short siRandHor = 0;
    //counters
    short siCounter = 0;

    std::cout << "Randomizing wall";

    while (siCounter < 10)
    {
    siRandVer = random(8); //randomize vertical coordinate
    Sleep(5);
    siRandHor = random(8); //randomize horizontal coordinate
    if (siCompGrid[siRandVer][siRandHor + 4][1] == 0) //check to see if randomized location is valid
    {
    siCompGrid[siRandVer][siRandHor + 4][1] = 1; //place wall
    siCompGrid[siRandVer][siRandHor + 4][2] = 50; //set wall hp
    siCounter++; //add to loop counter
    }
    std::cout << ".";
    }

    //set installation
    for(siCounter = 0; siCounter < 2; siCounter++)
    {
    siCompGrid[3 + siCounter][15][0] = 2;
    siCompGrid[3 + siCounter][15][1] = 5;
    siCompGrid[3 + siCounter][15][2] = 50;
    }

    std::cout << endl << "Wall radomization complete" << endl;

    return siCompGrid[8][16][5];
    }

    short random(short siLimit)
    {
    short siRand = 0;
    srand(GetTickCount());
    siRand = rand() % siLimit;
    return siRand;
    }

    short difficulty()
    {
    short siDifficulty = 0;

    do
    {
    if (siDifficulty != 0 && siDifficulty != 1)
    std::cout << "Error, please enter a value of 0 or 1" << endl;
    std::cout << "Please select difficulty (0 = Moderate, 1 = Challenging): ";
    std::cin >> siDifficulty;
    } while (siDifficulty != 0 && siDifficulty != 1);

    if (siDifficulty == 0)
    std::cout << "You have selected moderate difficulty" << endl;

    else
    std::cout << "You have selected challenging difficulty" << endl;


    return siDifficulty;
    }

    void briefing()
    {
    short siRedisplay = 1;
    std::cout << endl << "Welcome to mission control" << endl;
    Sleep(250);
    std::cout << "Your mission:" << endl;
    Sleep(250);
    std::cout << "1. Locate last enemy installation" << endl;
    Sleep(250);
    std::cout << "2. Destroy last enemy installation" << endl;
    Sleep(250);
    std::cout << "3. Destroy remaining enemy foreces" << endl;
    Sleep(250);
    std::cout << "Press any key to activate your monitor" << endl;
    Sleep(250);
    std::cout << "It will display recent surveillance in that area" << endl;
    Sleep(250);

    system("pause"); //outputs press any key to continue

    while (siRedisplay == 1)
    {
    //display animations
    clrscr(); //function which clears screen

    std::cout << "Recent Surveillance" << endl;
    std::cout << "2/28/03 18:16:26" << endl;
    std::cout << "----*" << endl;
    std::cout << " |" << endl;
    std::cout << " |" << endl;
    std::cout << " |" << endl;
    std::cout << " T|" << endl;
    std::cout << " T|" << endl;
    std::cout << " |" << endl;
    std::cout << " |" << endl;
    std::cout << " |" << endl;
    std::cout << "----*" << endl;
    Sleep(100);
    clrscr(); //function which clears screen

    std::cout << "Recent Surveillance" << endl;
    std::cout << "2/28/03 18:16:27" << endl;
    std::cout << "----*" << endl;
    std::cout << "----+-*" << endl;
    std::cout << " | |" << endl;
    std::cout << " | |" << endl;
    std::cout << " T| |" << endl;
    std::cout << " T| |" << endl;
    std::cout << " | |" << endl;
    std::cout << " | |" << endl;
    std::cout << "----+-*" << endl;
    std::cout << "----*" << endl;
    Sleep(100);
    clrscr(); //function which clears screen

    std::cout << "Recent Surveillance" << endl;
    std::cout << "2/28/03 18:16:28" << endl;
    std::cout << "----*" << endl;
    std::cout << " |" << endl;
    std::cout << "*---+*" << endl;
    std::cout << "| ||" << endl;
    std::cout << "| T||" << endl;
    std::cout << "| T||" << endl;
    std::cout << "| ||" << endl;
    std::cout << "*---+*" << endl;
    std::cout << " |" << endl;
    std::cout << "----*" << endl;
    Sleep(100);
    clrscr(); //function which clears screen

    std::cout << "Recent Surveillance" << endl;
    std::cout << "2/28/03 18:16:29" << endl;
    std::cout << "----*" << endl;
    std::cout << " |" << endl;
    std::cout << " |" << endl;
    std::cout << " *--*" << endl;
    std::cout << " | T|" << endl;
    std::cout << " | T|" << endl;
    std::cout << " *--*" << endl;
    std::cout << " |" << endl;
    std::cout << " |" << endl;
    std::cout << "----*" << endl;
    Sleep(100);
    clrscr(); //function which clears screen

    std::cout << "Recent Surveillance" << endl;
    std::cout << "2/28/03 18:16:30" << endl;
    std::cout << endl;
    std::cout << endl;
    std::cout << endl;
    std::cout << " *--*" << endl;
    std::cout << " | T|" << endl;
    std::cout << " | T|" << endl;
    std::cout << " *--*" << endl;
    Sleep(100);
    clrscr(); //function which clears screen

    std::cout << "Recent Surveillance" << endl;
    std::cout << "2/28/03 18:16:31" << endl;
    std::cout << endl;
    std::cout << endl;
    std::cout << "*----*" << endl;
    std::cout << "| |" << endl;
    std::cout << "| T |" << endl;
    std::cout << "| T |" << endl;
    std::cout << "| |" << endl;
    std::cout << "*----*" << endl;
    Sleep(100);
    clrscr(); //function which clears screen

    std::cout << "Recent Surveillance" << endl;
    std::cout << "2/28/03 18:16:32" << endl;
    std::cout << endl;
    std::cout << "*------*" << endl;
    std::cout << "| |" << endl;
    std::cout << "| |" << endl;
    std::cout << "| -\\ |" << endl;
    std::cout << "| -/ |" << endl;
    std::cout << "| |" << endl;
    std::cout << "| |" << endl;
    std::cout << "*------*" << endl;
    Sleep(100);
    clrscr(); //function which clears screen

    std::cout << "Recent Surveillance" << endl;
    std::cout << "2/28/03 18:16:33" << endl;
    std::cout << "*--------*" << endl;
    std::cout << "| |" << endl;
    std::cout << "| |" << endl;
    std::cout << "| /| |" << endl;
    std::cout << "| |-\\ |" << endl;
    std::cout << "| |-/ |" << endl;
    std::cout << "| \\| |" << endl;
    std::cout << "| |" << endl;
    std::cout << "| |" << endl;
    std::cout << "*--------*" << endl;
    Sleep(100);
    clrscr(); //function which clears screen

    std::cout << "Recent Surveillance" << endl;
    std::cout << "2/28/03 18:16:33 - PAUSED" << endl;
    std::cout << "*--------*" << endl;
    std::cout << "| |" << endl;
    std::cout << "| |" << endl;
    std::cout << "| /| |" << endl;
    std::cout << "| |-\\ |" << endl;
    std::cout << "| |-/ |" << endl;
    std::cout << "| \\| |" << endl;
    std::cout << "| | |" << endl;
    std::cout << "| |" << endl;
    std::cout << "*--------*" << endl;
    Sleep(100);
    clrscr(); //function which clears screen

    std::cout << "Recent Surveillance" << endl;
    std::cout << "2/28/03 18:16:33 - PAUSED" << endl;
    std::cout << "*--------*" << endl;
    std::cout << "| |" << endl;
    std::cout << "| |" << endl;
    std::cout << "| /| |" << endl;
    std::cout << "| |-\\ |" << endl;
    std::cout << "| |-/ |" << endl;
    std::cout << "| \\| |" << endl;
    std::cout << "| | |" << endl;
    std::cout << "| | |" << endl;
    std::cout << "*--------*" << endl;
    Sleep(100);
    clrscr(); //function which clears screen

    std::cout << "Recent Surveillance" << endl;
    std::cout << "2/28/03 18:16:33 - PAUSED" << endl;
    std::cout << "*--------*" << endl;
    std::cout << "| |" << endl;
    std::cout << "| |" << endl;
    std::cout << "| /| |" << endl;
    std::cout << "| |-\\ |" << endl;
    std::cout << "| |-/ |" << endl;
    std::cout << "| \\| |" << endl;
    std::cout << "| | |" << endl;
    std::cout << "| | |" << endl;
    std::cout << "*----|---*" << endl;
    Sleep(100);
    clrscr(); //function which clears screen

    std::cout << "Recent Surveillance" << endl;
    std::cout << "2/28/03 18:16:33 - PAUSED" << endl;
    std::cout << "*--------*" << endl;
    std::cout << "| |" << endl;
    std::cout << "| |" << endl;
    std::cout << "| /| |" << endl;
    std::cout << "| |-\\ |" << endl;
    std::cout << "| |-/ |" << endl;
    std::cout << "| \\| |" << endl;
    std::cout << "| | |" << endl;
    std::cout << "| | |" << endl;
    std::cout << "*----|---*" << endl;
    std::cout << " T";
    Sleep(100);

    std::cout << "A"; AZ std::cout << "R"; AZ std::cout << "G"; AZ std::cout << "E"; AZ std::cout << "T"; std::cout << endl;

    do
    {
    if (siRedisplay != 0 && siRedisplay != 1)
    {
    std::cout << "Error, please enter a value of 0 or 1" << endl;
    }
    std::cout << "Redisplay recent surveillance? (0 = No, 1 = Yes): ";
    std::cin >> siRedisplay;
    } while (siRedisplay != 0 && siRedisplay != 1);
    }

    std::cout << endl << "Mission recap:" << endl;
    Sleep(250);
    std::cout << "1. Locate last enemy installation" << endl;
    Sleep(250);
    std::cout << "2. Destroy last enemy installation" << endl;
    Sleep(250);
    std::cout << "3. Destroy remaining enemy foreces" << endl;
    Sleep(250);
    std::cout << "Good luck!" << endl;

    system("pause"); //outputs press any key to continue
    clrscr(); //function which clears screen
    }

    short displaygrid(short siCompGrid[8][16][5])
    {
    //10-50, player units
    //50-90, comp units

    //counters
    short i; //vertical
    short j; //horizontal

    std::cout << "GAMEBOARD:" << endl;
    std::cout << " 1 1 1 1 1 1 1" << endl;
    std::cout << " 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6" << endl;
    std::cout << " *- - - - - - - - - - - - - - - -*" << endl;

    //set fog of war map

    for (i = 0; i < 8; i++)
    {
    setter(siPlayerGrid, siCompGrid, i, 0); //set first grid in row
    setter(siPlayerGrid, siCompGrid, i, 1); //set second grid in row
    for (j = 0; 2 < 16; j++)
    {
    if (siCompGrid[i][j][0] == 1)
    {
    setter(siPlayerGrid, siCompGrid, i, j);
    if (siCompGrid[i][j][1] == 0)
    {
    if (j - 1 > 0) //check left one
    {
    setter(siPlayerGrid, siCompGrid, i, j - 1);
    if (j - 2 > 0 && siCompGrid[i][j - 1][0] != 1 && siCompGrid[i][j + 1][1] != 1) //check left two
    {
    setter(siPlayerGrid, siCompGrid, i, j - 2);
    }
    }
    if (i - 1 > 0 && j - 1 > 0) //check left one, up one
    {
    setter(siPlayerGrid, siCompGrid, i - 1, j - 1);
    if (i - 2 > 0 && j - 2 > 0 && siCompGrid[i - 1][j - 1][0] != 1 && siCompGrid[i - 1][j - 1][1] != 1) //check left two, up two
    {
    setter(siPlayerGrid, siCompGrid, i - 2, j - 2);
    }
    }
    if (i - 1 > 0) //check up one
    {
    setter(siPlayerGrid, siCompGrid, i - 1, j);
    if (i - 2 > 0 && siCompGrid[i - 1][j][0] != 1 && siCompGrid[i - 1][j][1] != 1) //check up two
    {
    setter(siPlayerGrid, siCompGrid, i - 2, j);
    }
    }
    if (i - 1 > 0 && j + 1 < 16) //check right one, up one
    {
    setter(siPlayerGrid, siCompGrid, i - 1, j + 1);
    if (i - 2 > 0 && j + 2 < 16 && siCompGrid[i - 1][j + 1][0] != 1 && siCompGrid[i - 1][j + 1][1] != 1) //check right two, up two
    {
    setter(siPlayerGrid, siCompGrid, i - 2, j + 2);
    }
    }
    if (j + 1 < 16) //check right one
    {
    setter(siPlayerGrid, siCompGrid, i, j + 1);
    if (j + 2 < 16 && siCompGrid[i][j + 1][0] != 1 && siCompGrid[i][j + 1][1] != 1) //check right two
    {
    setter(siPlayerGrid, siCompGrid, i, j + 2);
    }
    }
    if (i + 1 > 0 && j + 1 < 16) //check right one, up down
    {
    setter(siPlayerGrid, siCompGrid, i + 1, j + 1);
    if (i + 2 > 0 && j + 2 < 16 && siCompGrid[i + 1][j + 1][0] != 1 && siCompGrid[i + 1][j + 1][1] != 1) //check right two, down two
    {
    setter(siPlayerGrid, siCompGrid, i + 2, j + 2);
    }
    }
    if (i + 1 > 0) //check down one
    {
    setter(siPlayerGrid, siCompGrid, i + 1, j);
    if (i + 2 > 0 && siCompGrid[i + 1][j][0] != 1 && siCompGrid[i + 1][j][1] != 1) //check down two
    {
    setter(siPlayerGrid, siCompGrid, i + 2, j);
    }
    }
    if (i + 1 > 0 && j - 1 > 0) //check left one, down one
    {
    setter(siPlayerGrid, siCompGrid, i + 1, j - 1);
    if (i + 2 > 0 && j - 2 > 0 && siCompGrid[i + 1][j - 1][0] != 1 && siCompGrid[i + 1][j - 1][1] != 1) //check left two, down two
    {
    setter(siPlayerGrid, siCompGrid, i + 2, j - 2);
    }
    }
    if (i - 1 > 0 && j - 2 > 0 && (siCompGrid[i][j - 1][0] != 1 && siCompGrid[i][j - 1][1] != 1) && (siCompGrid[i - 1][j - 1][0] != 1 && siCompGrid[i - 1][j - 1][1] != 1)) //check left one and left one, up one
    {
    setter(siPlayerGrid, siCompGrid, i - 1, j - 2);
    }
    if (i - 2 > 0 && j - 1 > 0 && (siCompGrid[i - 1][j - 1][0] != 1 && siCompGrid[i - 1][j - 1][1] != 1) && (siCompGrid[i - 1][j][0] != 1 && siCompGrid[i - 1][j][1] != 1)) //check left one, up one and up one
    {
    setter(siPlayerGrid, siCompGrid, i - 2, j - 1);
    }
    if (i - 2 > 0 && j + 1 < 16 && (siCompGrid[i - 1][j][0] != 1 && siCompGrid[i - 1][j][1] != 1) && (siCompGrid[i - 1][j + 1][0] != 1 && siCompGrid[i - 1][j + 1][1] != 1)) //check up one and right one, up one
    {
    setter(siPlayerGrid, siCompGrid, i - 2, j + 1);
    }
    if (i - 1 > 0 && j + 2 < 16 && (siCompGrid[i - 1][j + 1][0] != 1 && siCompGrid[i - 1][j + 1][1] != 1) && (siCompGrid[i][j + 1][0] != 1 && siCompGrid[i][j + 1][1] != 1)) //check right one, up one and right one
    {
    setter(siPlayerGrid, siCompGrid, i - 1, j + 2);
    }
    if (i + 1 < 8 && j + 2 < 16 && (siCompGrid[i][j + 1][0] != 1 && siCompGrid[i][j + 1][1] != 1) && (siCompGrid[i + 1][j + 1][0] != 1 && siCompGrid[i + 1][j + 1][1] != 1)) //check right one and right one, down one
    {
    setter(siPlayerGrid, siCompGrid, i + 1, j + 2);
    }
    if (i + 2 < 8 && j + 1 < 16 && (siCompGrid[i + 1][j + 1][0] != 1 && siCompGrid[i + 1][j + 1][1] != 1) && (siCompGrid[i + 1][j][0] != 1 && siCompGrid[i + 1][j][1] != 1)) //check right one, down one and down one
    {
    setter(siPlayerGrid, siCompGrid, i + 2, j + 1);
    }
    if (i + 1 < 8 && j - 1 > 0 && (siCompGrid[i + 1][j][0] != 1 && siCompGrid[i + 1][j][1] != 1) && (siCompGrid[i + 1][j - 1][0] != 1 && siCompGrid[i + 1][j - 1][1] != 1)) //check down one and left one, down one
    {
    setter(siPlayerGrid, siCompGrid, i + 1, j - 1);
    }
    if (i + 1 < 8 && j - 2 > 0 && (siCompGrid[i + 1][j - 1][0] != 1 && siCompGrid[i + 1][j - 1][1] != 1) && (siCompGrid[i][j - 1][0] != 1 && siCompGrid[i][j - 1][1] != 1)) //check left one, down one and left one
    {
    setter(siPlayerGrid, siCompGrid, i + 1, j - 2);
    }
    }
    if (siCompGrid[i][j][1] == 1)
    {
    if (i - 1 > 0) //checks if vertical greater than 0
    {
    setter(siPlayerGrid, siCompGrid, i - 1, j); //sets up one
    if (j - 1 > 0)
    {
    setter(siPlayerGrid, siCompGrid, i - 1, j - 1); //sets left one, up one
    }
    if (j + 1 < 16)
    {
    setter(siPlayerGrid, siCompGrid, i - 1, j + 1); //sets right one, up one
    }
    }
    if (i + 1 < 16) //checks if vertical is less than 16
    {
    setter(siPlayerGrid, siCompGrid, i + 1, j); //sets down one
    if (j - 1 > 0)
    {
    setter(siPlayerGrid, siCompGrid, i + 1, j - 1); //sets left one, down one
    }
    if (j + 1 < 16)
    {
    setter(siPlayerGrid, siCompGrid, i + 1, j + 1); //sets right one, down one
    }
    }
    if (j - 1 > 0)
    {
    setter(siPlayerGrid, siCompGrid, i, j - 1); //sets left one
    }
    if (j + 1 < 16)
    {
    setter(siPlayerGrid, siCompGrid, i, j + 1); //sets right one
    }
    }
    if (siCompGrid[i][j][1] == 2 || siCompGrid[i][j][1] == 3)
    {

    }
    }
    }
    }



    /*
    //prints fog of war map
    for (i = 0; i < 8; i++)
    {
    std::cout << CYAN << i + 1 << "|";
    for (j = 0; j < 16; j++)
    {
    if (siPlayerGrid[i][j][0] == 0) //check for neutral
    {
    if (siPlayerGrid[i][j][1] == 0) //check for blank space
    {
    std::cout << BLACK << " "; //display blank space
    }
    else if (siPlayerGrid[i][j][1] == 1) //check for wall
    {
    std::cout << CYAN << "W"; //display wall
    }
    }
    else if (siPlayerGrid[i][j][0] == 1) //check for player unit
    {
    if (siPlayerGrid[i][j][1] == 0) //check for tank
    {
    std::cout << WHITE << "T"; //display tank
    }
    else if (siPlayerGrid[i][j][1] == 1) //check for infantry
    {
    std::cout << WHITE << "I"; //display infantry
    }
    else if (siPlayerGrid[i][j][1] == 2) //check for sniper
    {
    std::cout << WHITE << "S"; //display sniper
    }
    else if (siPlayerGrid[i][j][1] == 3) //check for deployed sniper
    {
    std::cout << WHITE << "D"; //display deployed sniper
    }
    }
    else if (siPlayerGrid[i][j][0] == 2) //check for comp unit
    {
    if (siPlayerGrid[i][j][1] == 0) //check for tank
    {
    std::cout << RED << "T"; //display tank
    }
    else if (siPlayerGrid[i][j][1] == 1) //check for infantry
    {
    std::cout << RED << "I"; //display infantry
    }
    else if (siPlayerGrid[i][j][1] == 2) //check for sniper
    {
    std::cout << RED << "S"; //display sniper
    }
    else if (siPlayerGrid[i][j][1] == 3) //check for deployed sniper
    {
    std::cout << RED << "D"; //display deployed sniper
    }
    else if (siCompGrid[i][j][1] == 4) //check for installation
    {
    std::cout << RED << "T"; //display installation
    }
    }
    if (j < 15)
    {
    std::cout << BLACK << " ";
    }
    }
    std::cout << CYAN << "|" << endl;
    }

    std::cout << " *- - - - - - - - - - - - - - - -*" << endl;
    */

    /*
    //display entire grid
    for (i = 0; i < 8; i++)
    {
    std::cout << CYAN << i + 1 << "|";
    for (j = 0; j < 16; j++)
    {
    if (siCompGrid[i][j][0] == 0) //check for neutral
    {
    if (siCompGrid[i][j][1] == 0) //check for blank space
    {
    std::cout << BLACK << " "; //display blank space
    }
    else if (siCompGrid[i][j][1] == 1) //check for wall
    {
    std::cout << CYAN << "W"; //display wall
    }
    }
    else if (siCompGrid[i][j][0] == 1) //check for player unit
    {
    if (siCompGrid[i][j][1] == 0) //check for tank
    {
    std::cout << WHITE << "T"; //display tank
    }
    else if (siCompGrid[i][j][1] == 1) //check for infantry
    {
    std::cout << WHITE << "I"; //display infantry
    }
    else if (siCompGrid[i][j][1] == 2) //check for sniper
    {
    std::cout << WHITE << "S"; //display sniper
    }
    else if (siCompGrid[i][j][1] == 3) //check for deployed sniper
    {
    std::cout << WHITE << "D"; //display deployed sniper
    }
    }
    else if (siCompGrid[i][j][0] == 2) //check for comp unit
    {
    if (siCompGrid[i][j][1] == 0) //check for tank
    {
    std::cout << RED << "T"; //display tank
    }
    else if (siCompGrid[i][j][1] == 1) //check for infantry
    {
    std::cout << RED << "I"; //display infantry
    }
    else if (siCompGrid[i][j][1] == 2) //check for sniper
    {
    std::cout << RED << "S"; //display sniper
    }
    else if (siCompGrid[i][j][1] == 3) //check for deployed sniper
    {
    std::cout << RED << "D"; //display deployed sniper
    }
    else if (siCompGrid[i][j][1] == 4) //check for installation
    {
    std::cout << RED << "T"; //display installation
    }
    }
    if (j < 15)
    {
    std::cout << BLACK << " ";
    }
    }
    std::cout << CYAN << "|" << endl;
    }

    std::cout << " *- - - - - - - - - - - - - - - -*" << endl;
    */

    return siPlayerGrid[8][16][5];
    }

    short setter(short siPlayerGrid[8][16][5], short siCompGrid[8][16][5], short i, short j)
    {
    short k;

    for (k = 0; k < 5; k++) //loop through elements in third dimension
    {
    siPlayerGrid[i][j][k] = siCompGrid[i][j][k]; //set player grid equal to comp grid
    }

    return siPlayerGrid[8][16][5];
    }

    void buy(short siCompGrid[8][16][5], short siMoney[2])
    {
    //counters
    short siTotalUnits[2] = {0};
    short siPurchased[2] = {0};
    short siCounter[2] = {0};

    //misc
    short siCost = 0;
    short siDone = 1;
    short siDetails = 0;
    short siRand = 0;
    short siRandomize = 0;

    for (siCounter[0] = 0; siCounter[0] < 8; siCounter[0]++)
    {
    for (siCounter[1] = 0; siCounter[1] < 16; siCounter[1]++)
    {
    if (siCompGrid[siCounter[0]][siCounter[1]][0] == 1)
    {
    siTotalUnits[0]++;
    }
    if (siCompGrid[siCounter[0]][siCounter[1]][0] == 2)
    {
    siTotalUnits[1]++;
    }
    }
    }

    std::cout << "Welcome to the Galactic Armory" << endl;
    Sleep(250);

    while (siDone != 0) //player buy phase
    {
    status(siCompGrid); //display unit status

    std::cout << "ARMORY:" << endl;
    std::cout << " | | | | |Attack |Movement |" << endl;
    std::cout << "# |Unit |Price |Armor |Damage |Range |Range |Special Ability" << endl;
    std::cout << "1 |Tank |1000c |6 |4 |2 |1 |Splash Damage " << endl;
    std::cout << "2 |Infantry|200c |2 |2 |1 |2 |Double Attacks" << endl;
    std::cout << "3 |Sniper |100c |1 |1 |3 |3 |Deploy (1 Turn)" << endl << endl;

    if (siTotalUnits[0] == 0 && siTotalUnits[1] == 0)
    {
    do
    {
    if (siDetails != 0 && siDetails != 1)
    {
    std::cout << "Error, please enter a value of 0 or 1" << endl;
    }
    std::cout << "Would you like details on the units? (0 = No, 1 = Yes): ";
    std::cin >> siDetails;
    } while (siDetails != 0 && siDetails != 1);

    if (siDetails == 1)
    {
    std::cout << "Details:" << endl;
    std::cout << "Tank: Slow unit capable of large amounts of damage" << endl;
    std::cout << "Infantry: Moderate speed unit capable of medium amounts of damage" << endl;
    std::cout << "Sniper: Fast unit capable or small amounts of damage" << endl << endl;
    }
    }

    do
    {
    if (siDone != 0 && siDone != 1 && siDone != 2 && siDone != 3)
    {
    std::cout << "Error, please enter a value 0-4" << endl;
    }
    if (siDone != 0 && siTotalUnits[0] == 0)
    {
    std::cout << "Error, You must purchase at least one unit before you can continue to the battle phase" << endl;
    }
    std::cout << "Please select what you would like to buy (0 = Exit): ";
    std::cin >> siDone;
    if (siDone == 1)
    {
    siCost = 1000; //set cost to 1000
    }
    else if (siDone == 2)
    {
    siCost = 200; //set cost to 200
    }
    else if (siDone == 3)
    {
    siCost = 100; //set cost to 100
    }
    } while (siDone != 0 && siDone != 1 && siDone != 2 && siDone != 3 && siTotalUnits[0] == 0);

    if (siDone != 0)
    {
    std::cout << "Randomize placement? (0 = No, 1 = Yes): ";
    std::cin >> siRandomize;
    if (siRandomize == 0)
    {
    std::cout << " *-" << endl;
    for (siCounter[0] = 0; siCounter[0] < 8; siCounter[0]++)
    {
    std::cout << siCounter[0] + 1 << " |";
    if (siCompGrid[siCounter[0]][0][0] == 0) //check for neutral
    {
    if (siCompGrid[siCounter[0]][0][1] == 0) //check for blank space
    {
    std::cout << BLACK << " "; //display blank space
    }
    else if (siCompGrid[siCounter[0]][0][1] == 1) //check for wall
    {
    std::cout << CYAN << "W"; //display wall
    }
    }
    else if (siCompGrid[siCounter[0]][0][0] == 1) //check for player unit
    {
    if (siCompGrid[siCounter[0]][0][1] == 0) //check for tank
    {
    std::cout << WHITE << "T"; //display tank
    }
    else if (siCompGrid[siCounter[0]][0][1] == 1) //check for infantry
    {
    std::cout << WHITE << "I"; //display infantry
    }
    else if (siCompGrid[siCounter[0]][0][1] == 2) //check for sniper
    {
    std::cout << WHITE << "S"; //display sniper
    }
    else if (siCompGrid[siCounter[0]][0][1] == 3) //check for deployed sniper
    {
    std::cout << WHITE << "D"; //display deployed sniper
    }
    }
    std::cout << endl;
    }
    std::cout << " *-" << endl;
    do
    {
    if (siRand != 0 && siRand != 1 && siRand != 2 && siRand != 3 && siRand != 4 && siRand != 5 && siRand != 6 && siRand != 7)
    {
    std::cout << "Error, please enter a value 1-8 (Vertical Coordinate): " << endl;
    }
    std::cout << "Please select the location (1-8): ";
    std::cin >> siRand;
    siRand--;
    } while (siRand != 0 && siRand != 1 && siRand != 2 && siRand != 3 && siRand != 4 && siRand != 5 && siRand != 6 && siRand != 7);
    }
    else
    {
    do
    {
    siRand = random(8);
    } while (siCompGrid[siRand][0][0] != 0); //check type of unit at random location
    }
    }

    siPurchased[0];
    }

    std::cout << "Thank you for visiting the Armory" << endl << endl;
    Sleep(250);
    std::cout << "Logging off.";
    Sleep(250);
    std::cout << ".";
    Sleep(250);
    std::cout << "." << endl;
    std::cout << "Computer has logged onto the Galactic Armory" << endl;
    std::cout << "Computer purchasing" << endl;

    siDone = 1;

    while (siDone != 0) //comp buy phase
    {
    do
    {
    if (siDone == 1)
    {
    siCost = 1000; //set cost to 1000
    }
    else if (siDone == 2)
    {
    siCost = 200; //set cost to 200
    }
    else if (siDone == 3)
    {
    siCost = 100; //set cost to 100
    }
    else
    {
    if ((siMoney[1] - siCost) <= 0)
    {
    siDone = 0;
    }
    }
    } while (siDone != 0 && siDone != 1 && siDone != 2 && siDone != 3);
    }

    std::cout << endl << "Computer has logged-off the Galactic Armory" << endl;
    }

    void status(short siCompGrid[8][16][5])
    {
    short siCounter[2] = {0};
    short siMilitary[3] = {0};

    for (siCounter[0] = 0; siCounter[0] < 8; siCounter[0]++) //counts all units in players military
    {
    for (siCounter[1] = 0; siCounter[1] < 16; siCounter[1]++)
    {
    if (siCompGrid[siCounter[0]][siCounter[1]][0] == 1) //player checks
    {
    if (siCompGrid[siCounter[0]][siCounter[1]][1] == 0) //tank check
    {
    siMilitary[0]++;
    }
    else if (siCompGrid[siCounter[0]][siCounter[1]][1] == 1) //infantry check
    {
    siMilitary[1]++;
    }
    else if (siCompGrid[siCounter[0]][siCounter[1]][1] == 2) //sniper check
    {
    siMilitary[2]++;
    }
    else if (siCompGrid[siCounter[0]][siCounter[1]][1] == 3) //deployed sniper check
    {
    siMilitary[2]++;
    }
    }
    else if (siCompGrid[siCounter[0]][siCounter[1]][0] == 2) //comp checks
    {
    if (siCompGrid[siCounter[0]][siCounter[1]][1] == 0) //tank check
    {
    siMilitary[0]++;
    }
    else if (siCompGrid[siCounter[0]][siCounter[1]][1] == 1) //infantry check
    {
    siMilitary[1]++;
    }
    else if (siCompGrid[siCounter[0]][siCounter[1]][1] == 2) //sniper check
    {
    siMilitary[2]++;
    }
    else if (siCompGrid[siCounter[0]][siCounter[1]][1] == 3) //deployed sniper check
    {
    siMilitary[2]++;
    }
    }
    }
    }

    std::cout << "MILITARY STATUS:" << endl;
    std::cout << "Tanks | "<< siMilitary[0] << endl;
    std::cout << "---------|---------" << endl;
    std::cout << "Infantry | "<< siMilitary[1] << endl;
    std::cout << "---------|---------" << endl;
    std::cout << "Sniper | "<< siMilitary[2] << endl;
    std::cout << "---------|---------" << endl;
    std::cout << "CREDITS:" << siMoney[0] << endl;
    }

    void clrscr() //function which clears screen
    {
    COORD coordScreen = { 0, 0 };
    DWORD cCharsWritten;
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    DWORD dwConSize;
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    GetConsoleScreenBufferInfo(hConsole, &csbi);
    dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
    FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
    GetConsoleScreenBufferInfo(hConsole, &csbi);
    FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
    SetConsoleCursorPosition(hConsole, coordScreen);
    }


    Error location wasn't specified. I posted all my code.

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    51

    Sorry

    Sorry about the bracket placements. They were all realigned when I pasted the code into the forum.

  6. #6
    julie lexx... btq's Avatar
    Join Date
    Jun 2002
    Posts
    161
    please use code tags

    and the funciton doesn't have any code...
    the prototype of displaygrid
    doesn't match the body..
    Code:
    short displaygrid(short siPlayerGrid[8][16][5], short siCompGrid[8][16][5]); //function displaying grid
    doesn't match
    Code:
    short displaygrid(short siCompGrid[8][16][5])
    {
    //10-50, player units
    //50-90, comp units
    ...
    
    }
    as you can see the declaration takes 2 arguments but the code for what I guess is supposed to be the function only takes 1
    and so it isn't the same function...maybe this function is in another
    file ?

    /btq
    ...viewlexx - julie lexx

  7. #7
    Registered User
    Join Date
    Feb 2003
    Posts
    51

    Please Accept My Gratitude

    I just realized that a minute ago. I was going to post that I figured it out, but you got there ahead of me, LOL. Thanks!

  8. #8
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    General comments on errors & debugging...

    That error message looks like a linker error (?) Link errors can be especially cryptic because they don't point to a particular line of source code, and your functions and variables are sort-of renamed.

    Compilers can often get confused. I've had the compiler report a few hundred errors because of one little misplaced bracket.

    So, the compiler and linker error messages are only a starting point. And, they won't help you with logical errors (where your program compiles and links without errors, but doesn't do what you expect.)

    1- Compile often. Put extra cout statements in your code so you can "see" what is going on. When you write a function, create an empty function first with a dummy return value (if any) to make sure that the function is being called correctly... etc. If you compile and test your code often, you won't have as much difficulty finding the errors. It takes some practice to learn where to start, and how to develop code in a sequence that is testable as you proceed.

    2- If you're using an IDE (Integrated Development Environment like Microsoft Visual C++), there is probably a degugger tool that will allow you to insert break points to stop and examine variable values etc.
    Last edited by DougDbug; 03-06-2003 at 01:15 PM.

  9. #9
    Registered User
    Join Date
    Feb 2003
    Posts
    51
    Thanks!

  10. #10
    Registered User
    Join Date
    Feb 2003
    Posts
    51
    You guys would never believe what I just did. I was trying to install Linux, so I had to repartition my computer. To my surprise, the backup drive where I placed all my C++ files was formatted. I suddenly realized the program I worked for over the last week was lost. I then realized that I had posted my code on the net for others to debug.

    Thank you all who asked me to post my code. You saved my weeks work!!!

    "Little things can be of large revelance" - Me (March 6th, 2003)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  3. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  4. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM