hi i am making a 16puzzle game and i keep getting error about parameter conversion in main function. maybe someone can help me out and figure out whats wrong? i had this program written with functions and it worked perfectly,but now making it with classes(coz my teacher requires classes in this project). maybe someone can help me out and fix the problems that are here? thank you!

the main function works untill line "obj.Move(Board, eNextMove);" and it keeps on giving me error.

main.cpp file

#include <iostream>
#include <ctime>
#include <windows.h>
#include "boardclass.h"

using namespace std;

int main() {
puzzle obj;
obj.InitializeBoard();
obj.Randomize();
char Board[4][4];
enum EMove    {	keUp = 'w',
				keDown = 's',
				keLeft = 'a',
				keRight = 'd'};
	do {
	obj.PrintBoard();
		cout << endl << "w = Up, s = Down, a = Left, d = Right" << endl;
		char cNextMove;
		cin >> cNextMove;
    	EMove eNextMove = (EMove)cNextMove;
		obj.Move(Board, eNextMove);
		cout << endl;
		system("cls");
	} while (true);
cout << "Baigta" << endl;
return 0;
}

board.cpp file

#include <iostream>
#include <ctime>
#include <windows.h>
#include "boardclass.h"


void puzzle ::  InitializeBoard() {
	const char Initial[4][4] = {
			{'1', '2', '3', '4'},
			{'5', '6', '7', '8'},
			{'9', 'A', 'B', 'C'},
			{'D', 'E', 'F', ' '}
	};
	for (int Row = 0; Row < 4; ++Row) {
		for (int Col = 0; Col < 4; ++Col) {
			Board[Row][Col] =  Initial[Row][Col];


		}
	}
}


void puzzle ::  Randomize() {

	srand((unsigned int)time(0));
	for (int iIndex = 0; iIndex < 1000; ++iIndex) {
		const int kiNextMove = (rand() % 4);
		switch (kiNextMove) {
			case 0:
				{
					Move(Board, keUp);
					break;
				}
			case 1:
				{
					Move(Board, keDown);
					break;
				}
			case 2:
				{
					Move(Board, keLeft);
					break;
				}
			case 3:
				{
					Move(Board, keRight);
					break;
				}
		}
	}
}

void puzzle:: PrintBoard() {

	for (int Row = 0; Row < 4; ++Row) {
		for (int Col = 0; Col < 4; ++Col) {
			cout << Board[Row][Col];
		}
		cout << endl;
	}
}


void puzzle :: LocateSpace(int& irRow, int& irCol, char Board[4][4]) {
	for (int Row = 0; Row < 4; ++Row) {
		for (int Col = 0; Col < 4; ++Col) {
			if (Board[Row][Col] == ' ') {
				irRow = Row;
				irCol = Col;
			}
		}
	}
}

void puzzle :: Move(char Board[4][4], const EMove keMove) {
	int RowSpace;
	int ColSpace;
	LocateSpace(RowSpace, ColSpace, Board);
	int RowMove(RowSpace);
	int ColMove(ColSpace);
	switch (keMove) {
		case keUp:
			{
				RowMove = RowSpace - 1;
				break;
			}
		case keDown:
			{
				RowMove = RowSpace + 1;
				break;
			}
		case keLeft:
			{
				ColMove = ColSpace - 1;
				break;
			}
		case keRight:
			{
				ColMove = ColSpace + 1;
				break;
			}
	}

	if (RowMove >= 0 && RowMove < 4 && ColMove >= 0 && ColMove < 4) {
		Board[RowSpace][ColSpace]	= Board[RowMove][ColMove];
		Board[RowMove][ColMove]	= ' ';
	} 
}

boardclass.h file

#include <iostream>
#include <ctime>
#include <windows.h>

using namespace std;

class puzzle 

{ 

char Board[4][4];
char cNextMove;
int eNextMove;
int Row;
int Col;
enum EMove    {	keUp = 'w',
				keDown = 's',
				keLeft = 'a',
				keRight = 'd'};


public:

	void puzzle :: PrintBoard();
	void puzzle :: Move(char Board[4][4], const EMove keMove);
	void puzzle :: Randomize();


	void puzzle :: LocateSpace(int& irRow, int& irCol, char Board[4][4]);
	void puzzle :: InitializeBoard();
};

Can you be more specific about the information in the error?

I think the problem is with your definition of the EMove enum. The members of an enum are all integer constants, not chars. This means that keUp is not literally the char 'w', it's the integer 119, 's' is 115, 'a' is 97, and 'd' is 100. Do you know that those are the values you're getting back from EMove eNextMove = (EMove)cNextMove; ?

error C2664: 'Move' : cannot convert parameter 2 from 'enum main::EMove' to 'enum puzzle::EMove'

this is the error.

yes i know. when it was made with onyl function main worked, and had no problems with enumerations.

I'm trying to compile this on VS2008 and getting several hundred errors. What compiler are you using?

I am using microsoft visual c++ 6.0.
I have solved this problem by making the whole "do" cycle into a diferent method and i dont get error anymore.
but now i am trying to add a message when the puzzle is finished. i know that i should write something in while() but i tried things like while( board[4][4] == initial[4][4]) but didnt worked. any suggestions? :/

Your detection will depend on how the puzzle is determined to be solved. Since I don't know what kind(s) of puzzles these are, I really can't answer that for you.

What I will say though is that you may want to consider a "flag" variable of some sort that either the while condition is based on or is part of an if that triggers a "break".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.