Hi, I've got a puzzle game program consist of 2D array 2 rows x 3 cols.
The professor wants no changes to be made in puzzle.h, which is:

#ifndef _PUZZLE_H
#define _PUZZLE_H

#include <iostream>
#include <iomanip>
#include <stdlib.h>

using namespace std;

// Constants
const int COLS = 3;
const int ROWS = 2;

// Function prototypes
// Your cpp file must have the code for movePuzzle   
void movePuzzle(int puzzle[][COLS], char dir, int rowcol);
void initPuzzle(int puzzle[][COLS], unsigned int seed);

void initPuzzle(int puzzle[][COLS], unsigned int seed)
{
   /* Initialise the puzzle and scramble it around */

   int x, y;

   // initialise random number generator using the seed value
   srand(seed);

   // fill the puzzle
   for (y=0; y<ROWS; y++) {
      for (x=0; x<COLS; x++) {
         puzzle[y][x] = 1 + y * COLS + x;
      }
   }

   // scramble the puzzle
   for (y=0; y<=ROWS*COLS; y++) {
      if ((rand() % 2) == 0) {
         movePuzzle(puzzle, 'v', rand() % COLS); 
      }
      else {
         movePuzzle(puzzle, 'h', rand() % ROWS); 
      }
   } 
}

#endif

This is my puzzle.cpp which includes puzzle.h

/*****************************************************************************\
This is a C++ program that runs a puzzle game.
The puzzle consist of 2 row x 3 column grid.
Grid filled with numbers 1 to 6 in random order.

The main aim of this puzzle game is to get user swap those number so that
they are in order (with number 1 in top left and 6 in bottom right).
\*****************************************************************************/

#include "puzzle.h"

int main(int argc, char *argv[])
{
    int puzzle[ROWS][COLS];
    
    initPuzzle(); ?????
    
    cout << "vn : " << "(0 <= n <= 2) to move column n down 1 position" << "\n";
    cout << "hn : " << "(0 <= n <= 1) to move row n right 1 position" << "\n";
    cout << "i  : " << "to print these instructions" << "\n";
    cout << "q  : " << "to quit" << "\n";
    
    system("PAUSE");
    return 0;
}

void movePuzzle(int puzzle[][COLS], char dir, int rowcol)
{
}

My problem is to call initPuzzle function before any other code.
I need to pass array and seed using command line argument.
I'm new to C++, can someone explain how to do that? (the line with ????)

initPuzzle function suppose to set up the puzzle and randomise it.
The function itself is in the puzzle.h and I can only call it in the puzzle.cpp (no changes can be made to puzzle.h).

Any help would be appreciated.

Recommended Answers

All 24 Replies

If im understanding you right, you need to populate the array from the command line.

So you should set up a command line function that is called just before initPuzzle(); ?????. Just make sure that the user only enters enough numbers to fill the array. You can do this in the commandLineArguments() function.
the prototype should look like this:
void commandLineArguments( int argc, char *argv[], int puzzle[][], int seed);

then just call initPuzzle(); with the correct arguments. initPuzzle(puzzle, seed)

If im understanding you right, you need to populate the array from the command line.

So you should set up a command line function that is called just before initPuzzle(); ?????. Just make sure that the user only enters enough numbers to fill the array. You can do this in the commandLineArguments() function.
the prototype should look like this:
void commandLineArguments( int argc, char *argv[], int puzzle[][], int seed);

then just call initPuzzle(); with the correct arguments. initPuzzle(puzzle, seed)

Hmm, so the command line function is a new function that I should declare inside the int main(int argc, char *argv[])?

I tried something like this:

int main(int argc, char *argv[])
{
    int puzzle[ROWS][COLS];
    
    void commandLineArguments(int argc, char *argv[], int puzzle[][COLS], unsigned int seed);
    
    initPuzzle(puzzle, seed);
    
    cout << "vn : " << "(0 <= n <= 2) to move column n down 1 position" << "\n";
    cout << "hn : " << "(0 <= n <= 1) to move row n right 1 position" << "\n";
    cout << "i  : " << "to print these instructions" << "\n";
    cout << "q  : " << "to quit" << "\n";
    
    system("PAUSE");
    return 0;
}

but the compiler complains:

in line initPuzzle(puzzle, seed);
`seed' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)

As Danny said, declare seed in main().
Second, to have the function modify a variable you need something like void foo(int &bar); note the "&".

I've been working on it for hours... >.<

So the program will take command line argument and pass it to initPuzzle right?

I'm a bit confused about the commandLineArguments function.
Can't I just use the convention main(int argc, char *argv[]) and then do something in the initPuzzle to receive those argument?

I've change my code to this:

/*****************************************************************************\
This is a C++ program that runs a puzzle game.
The puzzle consist of 2 row x 3 column grid.
Grid filled with numbers 1 to 6 in random order.

The main aim of this puzzle game is to get user swap those number so that
they are in order (with number 1 in top left and 6 in bottom right).
\*****************************************************************************/

#include "puzzle.h"

void commandLineArguments(int argc, char *argv[], int puzzle[][COLS], unsigned int seed);

int main(int argc, char *argv[])
{
    int seed;
    int puzzle[ROWS][COLS];
    
    commandLineArguments(argc, argv, puzzle, seed);
    
    initPuzzle(puzzle, seed);
    
    cout << "vn : " << "(0 <= n <= 2) to move column n down 1 position" << "\n";
    cout << "hn : " << "(0 <= n <= 1) to move row n right 1 position" << "\n";
    cout << "i  : " << "to print these instructions" << "\n";
    cout << "q  : " << "to quit" << "\n";
    
    system("PAUSE");
    return 0;
}

void commandLineArguments(int argc, char *argv[], int puzzle[][COLS], unsigned int seed)
{
}

void movePuzzle(int puzzle[][COLS], char dir, int rowcol)
{
}

but i'm still not sure what goes in the commandLineArguments function.
I'm still banging my head against the wall in learning command line argument and passing it into function as array.

Can someone explain what should I do so that the puzzle array can be set up and randomise through initPuzzle? >.<

Can someone explain specifically about command line argument?

Hmm, I've been working on it again for 2 hours now...
this all I got... When I tried to print the puzzle array, it just display some random memory. I have no idea what seem to be the problem.

/*****************************************************************************\
This is a C++ program that runs a puzzle game.
The puzzle consist of 2 row x 3 column grid.
Grid filled with numbers 1 to 6 in random order.

The main aim of this puzzle game is to get user swap those number so that
they are in order (with number 1 in top left and 6 in bottom right).
\*****************************************************************************/

#include "puzzle.h"

void commandLineArguments(int argc, char *argv[], int puzzle[][COLS], unsigned int seed);

int main(int argc, char *argv[])
{
    int seed;
    int puzzle[ROWS][COLS];
    
    commandLineArguments(argc, argv, puzzle, seed);
    
    initPuzzle(puzzle, seed);
    
    cout << "vn : " << "(0 <= n <= 2) to move column n down 1 position" << "\n";
    cout << "hn : " << "(0 <= n <= 1) to move row n right 1 position" << "\n";
    cout << "i  : " << "to print these instructions" << "\n";
    cout << "q  : " << "to quit" << "\n";
    
    cout << puzzle;
    
    system("PAUSE");
    return 0;
}

void commandLineArguments(int argc, char *argv[], int puzzle[][COLS], unsigned int seed)
{
     if (argc != 2)
     {
          cout << "Please enter right number of argument";
     }
     
     &seed = atoi (argv[1]);
     
}

void movePuzzle(int puzzle[][COLS], char dir, int rowcol)
{
}

You can't cout a 2d array like that. You'll have to make a nested loop, which loops trough all the elements in the array and prints them one at a time.

Hey there, first up you need to decide exactly what you are going to be passing via the command line when the program is called..
i.e. perhaps you're going to call the program and pass the numbers to populate the array and the seed..
The numbers used are 1 to 6 and for the sake of argument, we'll use a seed of 45 which gives us a total of 7 parameters..

So for this example you'll end up calling the puzzle program passing 1 2 3 4 5 6 and 45 as parameters.

ok, thats all straightforward so far..

The purpose of your commandlinearguments function is to parse the arguments passed into the main function to try to extract the bits you want to use.

Personally I'd rename the commandlinearguments function to parseCommandLineArguments (cause that's what it's doing) and make it return a bool (to denote whether the parsing succeded or failed)....Alternatively, make it return an int and use 1 for success and 0 for failure!

So you'd have something like this:

/*****************************************************************************\
This is a C++ program that runs a puzzle game.
The puzzle consist of 2 row x 3 column grid.
Grid filled with numbers 1 to 6 in random order.

The main aim of this puzzle game is to get user swap those number so that
they are in order (with number 1 in top left and 6 in bottom right).
\*****************************************************************************/

#include "puzzle.h"

// NOTE: return type set to bool to indicate whether or not parsing was successful! (or you could use int as a return type using 1 for true and 0 for false!) 
bool parseCommandLineArguments(int argc, char *argv[], int puzzle[][COLS], unsigned int &seed); // seed passed as a reference, so we can modify it's contents...alteratively a pointer would suffice! (change & to *)

int main(int argc, char *argv[])
{
	unsigned int seed;   // NOTE: in your .h file, seed is an unsigned int!
	int puzzle[ROWS][COLS];
 
 	// as long as parsing of the command line succeeds, then we can setup and play the game...
	if ( parseCommandLineArguments(argc, argv, puzzle, seed) )
    	{
		initPuzzle(puzzle, seed);
		
		cout << "vn : " << "(0 <= n <= 2) to move column n down 1 position" << "\n";
		cout << "hn : " << "(0 <= n <= 1) to move row n right 1 position" << "\n";
  		cout << "i : " << "to print these instructions" << "\n";
		cout << "q : " << "to quit" << "\n";
		// I'm guessing you'll be putting your main game loop somewhere in here at some point!
      	}
      	
      	// You'll end up here at the end of the game loop or if parsing fails..
  	system("PAUSE");
	return 0;
}

bool parseCommandLineArguments(int argc, char *argv[], int puzzle[][COLS], unsigned int &seed)
{
	// if there are 7 parameters, then we're ok to continue parsing
	if(argc==7)
	{
		// Now all you have to do is loop through the parameters in argv, strip out any control characters (i.e. '/' if you passed /1 /2 /3 /4 /5 /6 /45 as params) 
		// check that they are valid i.e. numerical and not characters
		// If valid, copy them to the appropriate place, either the puzzle array or the seed
		// else display an appropriate error message and return false (parsing failed)
		 
		return true; // if you get this far without returning false, then the parsing is complete and successful
	}
	else
	{
		// Show an error message: parsing failed due to an incorrect number of parameters
		return false;
	}
}

I hope that makes some sense, I purposely haven't filled in all of the blanks for you. But fingers crossed, that should be enough for you to get on with and find your way forward!

Hmm, I've been working on it again for 2 hours now...
this all I got... When I tried to print the puzzle array, it just display some random memory. I have no idea what seem to be the problem.

/*****************************************************************************\
This is a C++ program that runs a puzzle game.
The puzzle consist of 2 row x 3 column grid.
Grid filled with numbers 1 to 6 in random order.

The main aim of this puzzle game is to get user swap those number so that
they are in order (with number 1 in top left and 6 in bottom right).
\*****************************************************************************/

#include "puzzle.h"

void commandLineArguments(int argc, char *argv[], int puzzle[][COLS], unsigned int seed);

int main(int argc, char *argv[])
{
    int seed;
    int puzzle[ROWS][COLS];
    
    commandLineArguments(argc, argv, puzzle, seed);
    
    initPuzzle(puzzle, seed);
    
    cout << "vn : " << "(0 <= n <= 2) to move column n down 1 position" << "\n";
    cout << "hn : " << "(0 <= n <= 1) to move row n right 1 position" << "\n";
    cout << "i  : " << "to print these instructions" << "\n";
    cout << "q  : " << "to quit" << "\n";
    
    cout << puzzle;
    
    system("PAUSE");
    return 0;
}

void commandLineArguments(int argc, char *argv[], int puzzle[][COLS], unsigned int seed)
{
     if (argc != 2)
     {
          cout << "Please enter right number of argument";
     }
     
     &seed = atoi (argv[1]);
     
}

void movePuzzle(int puzzle[][COLS], char dir, int rowcol)
{
}

You can't cout a 2d array like that. You'll have to make a nested loop, which loops trough all the elements in the array and prints them one at a time.

Sorry I missed these posts as they were posted while I made the mammoth post above...Niek is quite correct, when trying to output the contents of a 2D array you need to set up some nested loops to loop through the entire array and output each item individually.

The reason you got a seemingly random memory address output by the cout statement is because essentially your puzzle variable itself is a pointer...Any array object is automatically treated as a pointer. The value you were getting from your cout was the address of the first element of the array!

Hi Jason,
thanks a lot for the explanation. However, I want the program to take only 1 parameters for the seed (argv[1] will be assign to seed).
So I want to get rid of the parse function. Can I do it like:

/*****************************************************************************\
This is a C++ program that runs a puzzle game.
The puzzle consist of 2 row x 3 column grid.
Grid filled with numbers 1 to 6 in random order.

The main aim of this puzzle game is to get user swap those number so that
they are in order (with number 1 in top left and 6 in bottom right).
\*****************************************************************************/

#include "puzzle.h"

int main(int argc, char *argv[])
{
    unsigned int seed;
    int puzzle[ROWS][COLS];
    
    if (argc != 2)
    {
          cout << "Please enter right number of argument";
          return 1;
    }
     
    seed = atoi (argv[1]);
    
    initPuzzle(&puzzle, seed);
    
    cout << "vn : " << "(0 <= n <= 2) to move column n down 1 position" << "\n";
    cout << "hn : " << "(0 <= n <= 1) to move row n right 1 position" << "\n";
    cout << "i  : " << "to print these instructions" << "\n";
    cout << "q  : " << "to quit" << "\n";
    
    
    
    system("PAUSE");
    return 0;
}


void movePuzzle(int puzzle[][COLS], char dir, int rowcol)
{
}

would this works? I mean to populate the array (since the function to set up and populate the array is initPuzzle).

About converting the seed, you'd be better of using stringstream (atoi() is a poor choice for that). Below is a snippet for the
conversion ...

#include <sstream>
#include <iostream>
using namespace std;

int main(int argc, char * argv[])
{
	// only two arguments accepted, check ...
	if(argc != 2)
	{
		cout << "Wrong number of arguments: " << argc << endl;
		return 1;
	}
	
	// Initialize the stringstream object with the argument
	stringstream ss(argv[1]);
	unsigned int seed;

	// Try converting the seed
	if( ! (ss >> seed))
	{
		cout << "Invalid argument for seed: " << argv[1] << endl;
		return 1;
	}

	cout << "Got seed: " << seed << endl;

	return 0;
}

Hmm, I tried to print the 2D array:

#include "puzzle.h"

void printPuzzle(int puzzle[][COLS]);

int main(int argc, char *argv[])
{
    unsigned int seed;
    int puzzle[ROWS][COLS];
    
    if (argc != 2)
    {
          cout << "Please enter right number of argument";
          return 1;
    }
     
    seed = atoi (argv[1]);
    
    initPuzzle(puzzle, seed);
    
    cout << "vn : " << "(0 <= n <= 2) to move column n down 1 position" << "\n";
    cout << "hn : " << "(0 <= n <= 1) to move row n right 1 position" << "\n";
    cout << "i  : " << "to print these instructions" << "\n";
    cout << "q  : " << "to quit" << "\n";
    
    printPuzzle(puzzle);
    
    system("PAUSE");
    return 0;
}

void printPuzzle(int puzzle[][COLS])
{    
    int i,j;
     
	for(i = 0; i < ROWS; i++)
	{
		for(j = 0; j < COLS; j++)
			cout << " " << puzzle[i][j];
		    cout << endl;
	}
}

i ran the program and gives it input parameter

./a.out 1234

but it gives me this array output

1 2 3
4 5 6

which means the initPuzzle doesn't work.

However, this is the kind of function I'm expecting

| 0 1 2
-----+----------------------
0 | 5 3 6
1 | 4 2 1

any idea how to make the initPuzzle works (scramble the puzzle) and how to format the output so that I got that dash and lines?

About converting the seed, you'd be better of using stringstream (atoi() is a poor choice for that). Below is a snippet for the
conversion ...

#include <sstream>
#include <iostream>
using namespace std;

int main(int argc, char * argv[])
{
	// only two arguments accepted, check ...
	if(argc != 2)
	{
		cout << "Wrong number of arguments: " << argc << endl;
		return 1;
	}
	
	// Initialize the stringstream object with the argument
	stringstream ss(argv[1]);
	unsigned int seed;

	// Try converting the seed
	if( ! (ss >> seed))
	{
		cout << "Invalid argument for seed: " << argv[1] << endl;
		return 1;
	}

	cout << "Got seed: " << seed << endl;

	return 0;
}

Hi, umm... I appreciate the concern for using sstream. But the project specification requires me not to add any other library in the code. I'm not allowed to change the puzzle.h (that means no new library should be used). Sorry but that's the limitation I have

Hi, umm... I appreciate the concern for using sstream. But the project specification requires me not to add any other library in the code. I'm not allowed to change the puzzle.h (that means no new library should be used). Sorry but that's the limitation I have

Oh I see, let the professor have his/her ways then. But in the future, you know to avoid atoi() .

does anyone know how to make the initPuzzle works properly?

does anyone know how to make the initPuzzle works properly?

What code you have in movePuzzle(...)?

What code you have in movePuzzle(...)?

The function initPuzzle suppose to populate array, setup the puzzle and scramble the order of number.

So it will be something like
| 0 1 2
--------
0 | 1 6 3
1 | 2 5 4

the movePuzzle is to give command (input from user)
(v = vertical)/(h = horizontal) + number of column/row to be shifted.

for example (still related to array above) user input v0, it will shift
the first column down one square.

new array after user input:

| 0 1 2
--------
0 | 2 6 3
1 | 1 5 4

The function initPuzzle suppose to populate array, setup the puzzle and scramble the order of number.

As per the code you are given in puzzle.h, the scrambling of the puzzle is actually done by means of the movePuzzle(), hence I asked about its code. If you haven't coded it yet, your output will be the initialized puzzle, i.e. 1,2,3,4,5,6.

As per the code you are given in puzzle.h, the scrambling of the puzzle is actually done by means of the movePuzzle(), hence I asked about its code. If you haven't coded it yet, your output will be the initialized puzzle, i.e. 1,2,3,4,5,6.

Hmm,
but initPuzzle function is in the puzzle.h

void initPuzzle(int puzzle[][COLS], unsigned int seed)
{
   /* Initialise the puzzle and scramble it around */

   int x, y;

   // initialise random number generator using the seed value
   srand(seed);

   // fill the puzzle
   for (y=0; y<ROWS; y++) {
      for (x=0; x<COLS; x++) {
         puzzle[y][x] = 1 + y * COLS + x;
      }
   }

   // scramble the puzzle
   for (y=0; y<=ROWS*COLS; y++) {
      if ((rand() % 2) == 0) {
         movePuzzle(puzzle, 'v', rand() % COLS); 
      }
      else {
         movePuzzle(puzzle, 'h', rand() % ROWS); 
      }
   } 
}

so it should scramble the puzzle around right?

I think there is something wrong with 'seed', I convert the input from user in argv[1] to int and then assign it to seed.
From there, i pass seed to initPuzzle as argument, which should do the setup and scrambling.

movePuzzle is the part where user can swap the order around (but the scrambling should be done in initPuzzle)

so it should scramble the puzzle around right?

movePuzzle is the part where user can swap the order around (but the scrambling should be done in initPuzzle)

Hmm, but looking closely at initPuzzle(), it clearly achieves the scrambling by calling movePuzzle(...) on two occasions.

// scramble the puzzle
   for (y=0; y<=ROWS*COLS; y++) {
      if ((rand() % 2) == 0) {
         movePuzzle(puzzle, 'v', rand() % COLS); 
      }
      else {
         movePuzzle(puzzle, 'h', rand() % ROWS); 
      }
   }

So, this means that you have to write the code for movePuzzle(...) in order to have the puzzle scrambled. Once you have movePuzzle() coded, you can call it from the main() too (passing in the user's input).

Hmm, but looking closely at initPuzzle(), it clearly achieves the scrambling by calling movePuzzle(...) on two occasions.

// scramble the puzzle
   for (y=0; y<=ROWS*COLS; y++) {
      if ((rand() % 2) == 0) {
         movePuzzle(puzzle, 'v', rand() % COLS); 
      }
      else {
         movePuzzle(puzzle, 'h', rand() % ROWS); 
      }
   }

So, this means that you have to write the code for movePuzzle(...) in order to have the puzzle scrambled. Once you have movePuzzle() coded, you can call it from the main() too (passing in the user's input).

umm... thats right... lol sorry I didn't look close enough...
I'm frustrated with the output format, but I got it now.

So the next part is complete the movePuzzle function.

The project specification says:
movePuzzle expects to be given the puzzle array, a char variable of 'v' or 'h', representing whether a vertical column or horizontal row is to be moved, and another variable indicating which column or row is to be moved.

for (y=0; y<=ROWS*COLS; y++) {
      if ((rand() % 2) == 0) {
         movePuzzle(puzzle, 'v', rand() % COLS); 
      }
      else {
         movePuzzle(puzzle, 'h', rand() % ROWS); 
      }
   }

I'm still wandering about the code that suppose to go in movePuzzle

void movePuzzle(int puzzle[][COLS], char dir, int rowcol)

it takes 3 arguments right? the array puzzle, the char 'v' or 'h', and the third argument is the number of index correspond to the vertical/horizontal.

Do I use If function to swap the array around? >.<

I'm still wandering about the code that suppose to go in movePuzzle

void movePuzzle(int puzzle[][COLS], char dir, int rowcol)

it takes 3 arguments right? the array puzzle, the char 'v' or 'h', and the third argument is the number of index correspond to the vertical/horizontal.

Yes. A suggestion, maybe first exercise with a smaller problem, e.g. try to simulate the "(0 <= n <= 1) to move row n right 1 position".
You might have ...

const int COLS = 3;
int array[COLS] = {1,2,3};

// todo: shift the ints in the array right 1 position, after which 
// the array will be {3,1,2}

Hi, I'm back >.<

Been busy with other assignment.

Hmm, Yea I realize that I should use array shifting.
But I still have problem in the input

/*****************************************************************************\
This is a C++ program that runs a puzzle game.
The puzzle consist of 2 row x 3 column grid.
Grid filled with numbers 1 to 6 in random order.

The main aim of this puzzle game is to get user swap those number so that
they are in order (with number 1 in top left and 6 in bottom right).
\*****************************************************************************/

#include "puzzle.h"

void printPuzzle(int puzzle[][COLS]);
void movePuzzle(int puzzle[][COLS], char dir, int rowcol);

int main(int argc, char *argv[])
{
    unsigned int seed;
    int puzzle[ROWS][COLS];
    
    
    if (argc != 2)
    {
          cout << "Please enter right number of argument";
          return 1;
    }
     
    seed = atoi (argv[1]);
    
    initPuzzle(puzzle, seed);
        
    printPuzzle(puzzle);
    
    return 0;
}

void printPuzzle(int puzzle[][COLS])
{    
    int i, j;
   
    
    cout << "\n";
    cout << "vn : " << "(0 <= n <= 2) to move column n down 1 position" << "\n";
    cout << "hn : " << "(0 <= n <= 1) to move row n right 1 position" << "\n";
    cout << "i  : " << "to print these instructions" << "\n";
    cout << "q  : " << "to quit" << "\n";
    cout << "\n";
    cout << "\n";
    
    cout << setw(5) << "|" << setw(7) << "0" << setw(7) << "1" << setw(7) << "2" << "\n";
    cout << setw(5) << setfill('-') << "+" << setw(22) << setfill('-') << "\n";
    
    for(i = 0; i < ROWS; i++)
	{     
            if (i != 1)
            {
            cout << "0" << "   " << "|";
            
            
            for(j = 0; j < COLS; j++)
 
			cout << "      " << puzzle[i][j] ;
		    cout << endl;
            }
            else
            {
            cout << "1" << "   " << "|";
            
            
            for(j = 0; j < COLS; j++)
 
			cout << "      " << puzzle[i][j] ;
		    cout << endl;
            }
     }
     cout << "\n";
     cout << "Please enter next move : ";
 
     
}

void movePuzzle(int puzzle[][COLS], char dir, int rowcol)
{
     cin >> dir, rowcol;
     
}

Since the program requires user to input the direction followed by the number of index to be shifted, where should I put those input? in the movePuzzle? printPuzzle? or main?

At the moment i put it in movePuzzle.

The next difficulties for me will be connecting the variable dir and rowcol between function, because I want to make a if conditional statement.

e.g.

if (dir='v' && rowcol=0)
{
     //some code for vertical array shifting 1 element to the right (index 0)
}
else if (dir='v' && rowcol=1)
{
    //some code for vertical array shifting 1 element to the right (index 1)
}
else if (dir='v' && rowcol=2)
{
     //some code for vertical array shifting 1 element to the right (index 2)
}
else if (dir ='h' && rowcol = 0)
{
    //some code for horizontal array shifting 1 element to the right (index 0)
}
else if (dir='h' && rowcol = 1)
{
     //some code for horizontal array shifting 1 element to the right (index 1)
}

those code will go to movePuzzle

you are assigning dir = 'h', instead you should be checking if dir is equal to a specific char, same goes for rowcol.

What you want is to assign location of say [0][0] to [1][1], you cannot do simply by [0][0] = [1][1] as doing so will overwrite the values. Try using a temporary value and then assign temporary value i to [0][0], that way you will be able to assign [0][0] to [1][1] and then assign [1][1] to your temporary value :)

if (argc != 2)

{

cout << "Please enter right number of argument";

return 1;

}

 

seed = atoi (argv[1]);

 

initPuzzle(puzzle, seed);

 

printPuzzle(puzzle);

this is wrong, read the specs, he says

initPuzzle()

comes RIGHT after you declare puzzle array, he might deduct marks off you if he sees the code above.

Also I'm pretty sure our lecturer checks various forums (maybe even this one) so it wouldn't be very wise to post your entire code for him and/or other students to see :P

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.