LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   C++ hackers anyone? (http://www.linuxquestions.org/questions/programming-9/c-hackers-anyone-238824/)

Kane635 10-04-2004 07:22 PM

C++ hackers anyone?
 
#include <iostream.h>
using namespace std;

void initVars()
{
char board[9] = {'1', '2', '3', '4', '5', '6', '7', '8', '9'};
}

void displayBoard()
{
cout << " | | " << endl;
cout << " " << board[0] << " | " << board[1] << " | " << board[2] << " " << endl;
cout << "---|---|---" << endl;
cout << " " << board[3] << " | " << board[4] << " | " << board[5] << " " << endl;
cout << "---|---|---" << endl;
cout << " " << board[6] << " | " << board[7] << " | " << board[8] << " " << endl;
cout << " | | " << endl;
}

int main()
{
initVars();
displayBoard();
cin.ignore();
}

12 C:\Dev-Cpp\Untitled1.cpp `board' undeclared (first use this function)

Kane635 10-04-2004 07:30 PM

declaring board[8] gives...
6 C:\Dev-Cpp\Untitled1.cpp too many initializers for `char[8]'

tim1235 10-04-2004 07:37 PM

12 C:\Dev-Cpp\Untitled1.cpp `board' undeclared (first use this function)

You declare a board in InitVars() but don't do anything with it!

In you function main you call InitVars which creates a board array but then returns nothing! (void function). Your function displayBoard() then tries to use an unknown variable board. It either has to be passed to this function, or the board variable must be global.

You should either declare a global board or get you function InitVars to return the initalised board and then do something with it.


All times are GMT -5. The time now is 04:49 AM.