hey guys, this is another part of my program which I'm having a hard time with. For those who followed my previous post about displaying a board, now I'm trying to let the user swap the letters within the array. Something like this:
I'm not exactly how to do it with strings. Because comparing each inputed string to every one set up for the board positions would be extremely long. The approach I took will be probably long as well, but for now it is not working. In the code below, once the elements have been swapped and I want to display the board again, I get all Z's:Code:1 2 3 4 5 - - - - - A|A O E A E B|H E Y F U C|D T A A O D|L E S B I E|O W O S N Enter the coordinates of the locations to swap: A1 B5 1 2 3 4 5 - - - - - A|U O E A E B|H E Y F A C|D T A A O D|L E S B I E|O W O S N
any suggestions? maybe a totaly diferent aproach?Code:void displayTheBoard(float totalPercentArray[ ], char boardArray[][SIZE]) { int i; int j; int move = 1; cout << " 1 2 3 4 5\n" << " - - - - -\n"; for( i = 0; i < SIZE; i++) { cout << (char)(i + 'A') << "| "; for ( j = 0; j < SIZE; j++ ) { if( move == 1){ boardArray[i][j] = getCharacter(totalPercentArray); } cout << boardArray[i][j] << " "; } cout << endl; } move++; swapLetters(boardArray); } //============================================== void swapLetters(char boardArray[][SIZE]) { //declaring variables char letterFrom; char letterTo; int numberFrom; int numberTo; cout << "Enter the coordinates of the locations to swap: "; cin >> letterFrom >> numberFrom >> letterTo >> numberTo; letterFrom = toupper(letterFrom); letterTo = toupper(letterTo); comparePositions(letterFrom, numberFrom, letterTo, numberTo, boardArray); } //================================= void comparePositions(char row, int column, char row2, int column2, char boardArray[][SIZE]) { //declaring varaibles; char temp1; char temp2; //declaring arrays float totalPercentArray[LIMIT]; if( row == 'A' && column == 1) { if( row2 == 'A' && column2 == 2) { cout << "\n\nmaybe it will work\n\n"; temp1 = boardArray[0][0]; temp2 = boardArray[0][1]; boardArray[0][1] = temp1; boardArray[0][0] = temp2; cout << "first " << boardArray[0][1] << " second " << boardArray[0][0] << endl; } } displayTheBoard(totalPercentArray, boardArray); }
I'm also attaching the full code for those who want to compile it.
thanks,
axon



LinkBack URL
About LinkBacks


