C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-17-2009, 10:14 AM   #1
Registered User
 
Join Date: Apr 2009
Posts: 1
Question non-lvalue error

/*****
Name:Zackery Breeland Date Assigned:April 7, 2009
Course:CSE 1233 Date Due:April 17, 2009

File Name: zlb12Lab8.c

Program Description:
To create a tick tack toe game against a computer.
*****/

Code:
#include <stdio.h>
#include <stdlib.h>

void Board();
void Winner();
int selection(char, int);

int boxArray[3][3];
int box1, box2;
char square[3][3];
char winner;
int Player = 0;

int main()
{
	int x, y;
	int box1 = 0;
	int box2 = 0;
	int Player;
	int boxValue = 0;
	char square[box1][box2];
	
	Board();

/*Choose Square*/
	while(winner = ' ')
	{
		printf("%c", winner);

		if(Player == 1)
		{
			printf("X");
			printf("Choose a square position:  ");
			printf("Row:  ");
			scanf("%d", &box1);
			printf("Column:  ");
			scanf("%d", &box2);

		if(selection(square[3][3], Player) == 1)
			Player = 1;
		else
			Player = 2;
		}
		
		else
		{
			printf("O");
			printf("Choose a square position:  ");
			printf("Row:  ");
			scanf("%d", &box1);
			printf("Column:  ");
			scanf("%d", &box2);
			
		if(selection(square[3][3], Player) == 1)
			Player = 2;
		else
			Player = 1;
		}
	}


		Board();
		Winner();	

return 0;
}	

/*Selection*/
int selection(char square[box1][box2], int player)
{

	if(square[box1 - 1][box2 - 1] == '\0' && (player == 1 || player == 0))
	{
		square[box1 -1][box2 - 1] = 'x';
	return 0;
	}

	else if(square[box1 - 1][box2 - 1] == '\0' && player == 2)
	{
		square[box1 -1][box2 -1] == 'o';
	return 0;
	}

	else
		return 1;
}

/*Board*/
void Board()
{
	printf("   |   |   \n");
	printf("%c |%c |%c \n", square[0][0], square[0][1], square[0][2]);
	printf("   |   |   \n");
	printf("___________\n");
	printf("   |   |   \n");
	printf("%c |%c |%c \n", square[1][0], square[1][1], square[1][2]);
	printf("   |   |   \n");
	printf("___________\n");
	printf("   |   |   \n");
	printf("%c |%c |%c \n", square[2][0], square[2][1], square[2][2]);
	printf("   |   |   \n");
}

/*Who Won*/
void Winner()
{

	if (square[0][0] == 'x' && square[0][1] = 'x' && square[0][2] = 'x')
		winner = 'x';
	else if (square[1][0] == 'x' && square[1][1] == 'x' && square[1][2] == 'x')
		winner = 'x';
	else if (square[2][0] == 'x' && square[2][1] == 'x' && square[2][2] == 'x')
		winner = 'x';
	else if (square[0][0] == 'x' && square[1][0] == 'x' && square[2][0] == 'x')
		winner = 'x';
	else if (square[0][1] == 'x' && square[1][1] == 'x' && square[2][1] == 'x')
		winner = 'x';
	else if (square[0][2] == 'x' && square[1][2] == 'x' && square[2][2] == 'x')
		winner = 'x';
	else if (square[0][0] == 'x' && square[1][1] == 'x' && square[2][2] == 'x')
		winner = 'x';
	else if (square[0][2] == 'x' && square[1][1] == 'x' && square[2][0] == 'x')
		winner = 'x';
	else if (square[0][0] == 'o' && square[0][1] == 'o' && square[0][2] == 'o')
		winner = 'o';
	else if (square[1][0] == 'o' && square[1][1] == 'o' && square[1][2] == 'o')
		winner = 'o';
	else if (square[2][0] == 'o' && square[2][1] == 'o' && square[2][2] == 'o')
		winner = 'o';
	else if (square[0][0] == 'o' && square[1][0] == 'o' && square[2][0] == 'o')
		winner = 'o';
	else if (square[0][1] == 'o' && square[1][1] == 'o' && square[2][1] == 'o')
		winner = 'o';
	else if (square[0][2] == 'o' && square[1][2] == 'o' && square[2][2] == 'o')
		winner = 'o';
	else if (square[0][0] == 'o' && square[1][1] == 'o' && square[2][2] == 'o')
		winner = 'o';
	else if (square[0][2] == 'o' && square[1][1] == 'o' && square[2][0] == 'o')
		winner = 'o';
	else
		printf("CAT");

	if(winner == 'x')
	{
		printf("x wins");
	return;
	}

	if(winner == 'o')
	{
		printf("o wins");
	return;
	}
}

// After this point the program gives me a non-lvalue in assignment on line 118 in void Winner(). Does anyone know what is wrong. I just can't get this thing to work.
zlb12 is offline   Reply With Quote
Old 04-17-2009, 10:43 AM   #2
Registered User
 
Join Date: Sep 2004
Location: California
Posts: 2,845
Code:
if (square[0][0] == 'x' && square[0][1] = 'x' && square[0][2] = 'x')
You are doing assignment here, not comparing. Note the single equals sign instead of the double equals.
bithub is offline   Reply With Quote
Reply

Tags
error, lvalue, non working, program problem

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting an error with OpenGL: collect2: ld returned 1 exit status Lorgon Jortle C++ Programming 6 05-08-2009 08:18 PM
An error is driving me nuts! ulillillia C Programming 5 04-04-2009 09:15 PM
Making C DLL using MSVC++ 2005 chico1st C Programming 26 05-28-2008 01:17 PM
Connecting to a mysql server and querying problem Diod C++ Programming 8 02-13-2006 10:33 AM
Couple C questions :) Divx C Programming 5 01-28-2003 01:10 AM


All times are GMT -6. The time now is 06:22 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22