Jump to content
  • Advertisement
Sign in to follow this  
Avont29

code doesn't work

This topic is 4844 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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; }

Share this post


Link to post
Share on other sites
Advertisement
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?

Share this post


Link to post
Share on other sites
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 '

Share this post


Link to post
Share on other sites
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 specifiers
c:\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 specifiers
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(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 0
c:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(22) : error C2087: 'board' : missing subscript
c:\Documents and Settings\gunning\Desktop\System\Development\ef\ef\ef.cpp(22) : error C2501: 'board' : missing storage-class or type specifiers
c:\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 arrays
c:\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 specifiers
c:\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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!