4 Replies - 918 Views - Last Post: 25 June 2009 - 07:08 PM Rate Topic: -----

#1 mono15591   User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 406
  • Joined: 05-November 08

I get an error with my array in my loop

Post icon  Posted 25 June 2009 - 05:36 PM

Well I'm just trying to write my tic-tac-toe board and Im getting an error with my array.

 for (int n=0;n!=8;n++)
		{
			if (n==2|n==5|n==8)
			   cout<<" "<<cNum[n]<<endl;
			else
			   count<<" "<<cNum[n];
		}



Error:
22 C:\Dev-Cpp\Projects\TicTacToe\main.cpp invalid operands of types `<unknown type>' and `const char[2]' to binary `operator<<'



This is all of it so far. The only thing I'm trying to do right now is display the board and do a check of the move the player made.
#include <cstdlib>
#include <iostream>

using namespace std;


int main(int argc, char *argv[])
{
	char cNum[9] = {0,1,2,3,4,5,6,7,8};
	char cPlayerMove;
	bool bTurn=true;
	bool bGameOver;
   
   do { 
		cout<<"Tic-Tac-Toe!"<<endl;
		
		for (int n=0;n!=8;n++)
		{
			if (n==2|n==5|n==8)
			   cout<<" "<<cNum[n]<<endl;
			else
			   count<<" "<<cNum[n];
		}
		
		cin>> cPlayerMove;
		
		for (int n=0;n!=8;n++)
		{
			if (cPlayerMove==cNum[n])
			{
			 if (cNum[n]!='X'|cNum[n]!='O')
			  if (bTurn==true)
				 cNum[n]='X';
			  else
				 cNum[n]='O';
			 else
				 cout<<"This position is taken"<<endl;
			  }
		}

	if (bTurn==true)
	   bTurn=false;
	else
	   bTurn=true;
  
	   
	} while( bGameOver != true );
	
	system("PAUSE");
	return EXIT_SUCCESS;
}


This post has been edited by mono15591: 25 June 2009 - 05:43 PM


Is This A Good Question/Topic? 0
  • +

Replies To: I get an error with my array in my loop

#2 Notorion   User is offline

  • D.I.C Regular

Reputation: 35
  • View blog
  • Posts: 378
  • Joined: 17-February 09

Re: I get an error with my array in my loop

Posted 25 June 2009 - 05:51 PM

here is your problem
//your code
 if (n==2|n==5|n==8)

//new code
 if (n==2||n==5||n==8)




Was This Post Helpful? 0
  • +
  • -

#3 mono15591   User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 406
  • Joined: 05-November 08

Re: I get an error with my array in my loop

Posted 25 June 2009 - 05:56 PM

View PostNotorion, on 25 Jun, 2009 - 04:51 PM, said:

here is your problem
//your code
 if (n==2|n==5|n==8)

//new code
 if (n==2||n==5||n==8)





Well the "or" symbol works but I just found out
I put "count" instead of "cout" haha I've been staring at that line for 10 min arg

but now I have another question when this prints on the command promt thing I get little symbols instead of the numbers
Was This Post Helpful? 0
  • +
  • -

#4 ericr2427   User is offline

  • D.I.C Regular
  • member icon

Reputation: 40
  • View blog
  • Posts: 378
  • Joined: 01-December 08

Re: I get an error with my array in my loop

Posted 25 June 2009 - 06:38 PM

Use quotes when you define the char array.
char cNum[9] = {'1','2','3','4','5','6','7','8','9'};


Was This Post Helpful? 0
  • +
  • -

#5 mono15591   User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 406
  • Joined: 05-November 08

Re: I get an error with my array in my loop

Posted 25 June 2009 - 07:08 PM

View Postericr2427, on 25 Jun, 2009 - 05:38 PM, said:

Use quotes when you define the char array.
char cNum[9] = {'1','2','3','4','5','6','7','8','9'};




so simple
Thank you!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1