code doesn't work

Started by
13 comments, last by Avont29 18 years, 8 months ago
why doesn't this work? #include <iostream> using namespace std; int main(void) { const int ROWS= 3; const int COLUMNS= 3; char board[ROWS][COLUMNS]= { ('0', 'X', '0'), (` `, 'X', 'X'), ('X', '0', '0') }; cout<<"Here's the tic-tac-toe board:\n"; for(int i=0; i < ROWS; ++i) { for(int j=0; j<COLUMNS; ++j cout<< board[j]; cout<< endl; } board[1][0]= 'X'; for(int i= 0; i <ROWS; ++i) { for(int j= 0; j<COLUMNS; ++j cout<< board[j] cout<< endl; { cout<< "\n'X' wins!"; return 0; }
Advertisement
You are missing a closing bracket.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
where?

it also said something about stray in program
Usually its customery (sp?) to post the symptom of the problem along with the code.

I believe that the { should be } at the end of the second for loop.

also use [ source ] [/ source ] tags for source code.

Did you try to fix this problem yourself?
Quote:Original post by BosskIn Soviet Russia, you STFU WITH THOSE LAME JOKES!
Quote:Original post by Avont29
    char board[ROWS][COLUMNS]=    { ('0', 'X', '0'), (` `, 'X', 'X'), ('X', '0', '0') };                        ^ ^


You are using backticks ` instead of single-quotes '
Learn to understand what the compiler tells you. I actually see a lot of problems in that code. Take this sample for example:

for(int i= 0; i <ROWS; ++i)
{
for(int j= 0; j<COLUMNS; ++j
cout<< board[j]
cout<< endl;
{

You forgot a parenthesis. A semicolon. And a closing bracket.

But that's hardly the only problem. These are all the error messages I see.

c:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(11) : error C2018: unknown character '0x60'c:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(11) : error C2018: unknown character '0x60'c:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(11) : error C2059: syntax error : ','c:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(13) : error C2143: syntax error : missing ';' before '<<'c:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(13) : error C2501: 'cout' : missing storage-class or type specifiersc:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(15) : error C2059: syntax error : 'for'c:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(15) : error C2143: syntax error : missing ')' before ';'c:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(15) : error C2143: syntax error : missing ';' before '<'c:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(15) : error C2501: 'i' : missing storage-class or type specifiersc:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(15) : error C2059: syntax error : '++'c:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(15) : error C2059: syntax error : ')'c:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(16) : error C2143: syntax error : missing ';' before '{'c:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(16) : error C2447: '{' : missing function header (old-style formal list?)c:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(22) : error C2466: cannot allocate an array of constant size 0c:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(22) : error C2087: 'board' : missing subscriptc:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(22) : error C2501: 'board' : missing storage-class or type specifiersc:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(22) : error C2440: 'initializing' : cannot convert from 'char' to 'int [1][1]'        There are no conversions to array types, although there are conversions to references or pointers to arraysc:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(24) : error C2059: syntax error : 'for'c:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(24) : error C2143: syntax error : missing ')' before ';'c:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(24) : error C2143: syntax error : missing ';' before '<'c:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(24) : error C2501: 'i' : missing storage-class or type specifiersc:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(24) : error C2086: 'int i' : redefinition        c:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(15) : see declaration of 'i'c:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(24) : error C2059: syntax error : '++'c:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(24) : error C2059: syntax error : ')'c:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(25) : error C2143: syntax error : missing ';' before '{'c:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(25) : error C2447: '{' : missing function header (old-style formal list?)


You should go through each one and look at the problem line. Are you familiar with Visual C++ and how to analyze errors? It helps to be.

Asking others to fix your code is not good practice on these forums. Next time if you are having this problem, first look up the error and see what it means. A Google Groups search can help you here. Then fix the problem. If you still have errors, look them up and fix them. If you come to a problem that you just cannot fix, post it here along with any error messages and we'll do our best. But simply asking us to fix your code is not good practice here at GameDev.net.

And will you stop posting so many damn topics? Seven topics in two hours is a little excessive.
....[size="1"]Brent Gunning
Quote:Original post by skittleo
Learn to understand what the compiler tells you. I actually see a lot of problems in that code. Take this sample for example:

for(int i= 0; i <ROWS; ++i)
{
for(int j= 0; j<COLUMNS; ++j
cout<< board[j]
cout<< endl;
{

You forgot a parenthesis. A semicolon. And a closing bracket.

But that's hardly the only problem. These are all the error messages I see.

*** Source Snippet Removed ***

You should go through each one and look at the problem line. Are you familiar with Visual C++ and how to analyze errors? It helps to be.

Asking others to fix your code is not good practice on these forums. Next time if you are having this problem, first look up the error and see what it means. A Google Groups search can help you here. Then fix the problem. If you still have errors, look them up and fix them. If you come to a problem that you just cannot fix, post it here along with any error messages and we'll do our best. But simply asking us to fix your code is not good practice here at GameDev.net.

And will you stop posting so many damn topics? Seven topics in two hours is a little excessive.


oh, ok, sorry about so many posts, i'll keep it down, and i'll fix my code on my own, i don't need your help, heh

got it, i fixed my own code :) thanks for all the tips skitteo, you've helped me a lot
Quote:Original post by Avont29
got it, i fixed my own code :) thanks for all the tips skitteo, you've helped me a lot


Glad to hear you got it working. Don't take what I say personally. I only want you to be a productive member of GameDev.net.
....[size="1"]Brent Gunning
Haha, he's posted more in eight weeks than I have in three years [crying]

This topic is closed to new replies.

Advertisement