I am extremely new to C++, can sum1 tell me a faster way to output stuff than cout? It either outputs too slow or takes too long to automatically scroll or something. I was trying to sort of output and refresh in real time w cout

Can you explain a bit more on what you are trying to do? Better if you can post the code. Otherwise there will be a lot of answers based on a lot of assumptions.

its really big, prolly outside the limits for posts. Im getting way ahead of myself, making a program this big wen i know nothing and probably would be able to make the same program better if i wait until i know more. but, basically its a program for the 15 slider puzzle and it gets confusing/disorienting or watever cause the info is flashing too fast for you to really make moves as fsast as you would like.

Wow, i need to read what I write before i post. If anyone wants, i can email it so you can see what i mean.

No need to email. You can attach your program here. Make sure you attach code, and not the executable.

Fancy. Ty. Its like 1008 lines and not well commented, though. Atleast it only uses simple stuff.

Attachments
//
//
//           15 PUZZLE
//
//
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <time.h>
using namespace std;




int getCol(int pos)
{return pos%12;}

int getRow(int pos)
{return (int)(pos/12);}

int getPos(int col, int row)
{return row*12 + col;}




void dispPuz(int* current)
{
for (int i = 0; i < 144; i++)
{

if (*(current+i) == 0)
cout << "  ";
else
{
    if (*(current+i) == -1)
    cout << "--";
    else
    {
        if (*(current+i) == -2)
        cout << "?";
        else
        cout << *(current+i);
        
        if (*(current+i) < 10)
        cout << " ";
    } // end 'else'
    
    
    
} // end 'else'

cout << "   ";

if (getCol(i) == 11)
cout << "\n\n\n";
} // end 'for'
} // end dispPuz()




void move(int direction, int current[])
{
int row,col;

for (int i = 0; i < 144; i++)
{
if (current[i] == -1)
{
col = getCol(i);
row = getRow(i);
break;
} // end 'if'
} // end 'for'

if (direction == 1 && current[ getPos(col,row-1) ] != 0)
{
current[ getPos(col,row)] = current[ getPos(col,row-1)];
current[ getPos(col,row-1)] = -1;
} // end  up 'if'

if (direction == 2 && current[ getPos(col-1,row) ] != 0)
{
current[ getPos(col,row)] = current[ getPos(col-1,row)];
current[ getPos(col-1,row)] = -1;
} // end  left 'if'

if (direction == 3 && current[ getPos(col,row+1) ] != 0)
{
current[ getPos(col,row)] = current[ getPos(col,row+1)];
current[ getPos(col,row+1)] = -1;
} // end  down 'if'

if (direction == 4 && current[ getPos(col+1,row) ] != 0)
{
current[ getPos(col,row)] = current[ getPos(col+1,row)];
current[ getPos(col+1,row)] = -1;
} // end  right 'if'
} // end move()




int testWin(int current[], int solution[])
{
int win = 0;
int i;
for (i = 0; i < 144; i++)
{
if (current[i] != solution[i])
break;
} // end 'for'

if (i == 144)
win = 1;
return win;
} // end testWin()




void scramble(int current[])
{
srand(time(NULL));
for (int i = 0; i < 1000000; i++)
move(rand()%4+1, current);
} // end scramble()




void dispControls()
{
for (int i = 0; i < 59; i++)
cout << "\n";

cout << "CONTROLS\n\nQ   E\n\n  Z X C\n\nC - Display Controls\nE - Display "
<< "Solution\nZ - Scramble\nX - Solve (Not done yet)\nQ - Quit to Menu\n\n  "
<< "W\n A S D\n\nW - Move the number above the space down\nA - Move the number "
<< "to the left of the space right\nS - Move the number below the space "
<< "up\nD - Move the number to the right of the space left\n\n-You can put in "
<< "a sequence of letters.\n-Make sure Caps Lock is off.\n\n";
system("PAUSE");
} // end dispControls()




void dispControls2()
{
for (int i = 0; i < 59; i++)
cout << "\n";

cout << "CONTROLS\n\nQ   E\n\n      C\n\nC - Display Controls\nE - Change "
<< "the block\nQ - End customize\n\n  W\n A S D\n\nW - Move cursor up\nA - "
<< "Move cursor left\nS - Move cursor down\nD - Move cursor right\n\n-You "
<< "can put in a sequence of letters.\n-Make sure Caps Lock is off.\n\nCHANGING "
<< "THE BLOCK\n\n0  - Unused block\n#  - A sliding block\n-1 - The empty "
<< "space\n\n";
system("PAUSE");
} // end dispControls2()




void custom(int* solution)
{
int row = 1;
int col = 1;
char in;
int inNum, count;

int solution2[144];
for (int i = 0; i < 144; i++)
*(solution+i) = 0;

dispControls2();

for (;;) // input loop
{

for (int i = 0; i < 59; i++)
cout << "\n";

for (int i = 0; i < 144; i++)
solution2[i] = *(solution+i);
solution2[getPos(col,row)] = -2;
dispPuz(solution2);

cout << "Choice: ";
cin >> in;

switch (in)
{
/////////////////////
case 'w':
if (row != 1)
row--;
break;
/////////////////////
case 'a':
if (col != 1)
col--;
break;
/////////////////////
case 's':
if (row != 10)
row++;
break;
/////////////////////
case 'd':
if (col != 10)
col++;
break;
/////////////////////
case 'c':
dispControls2();
break;
/////////////////////
case 'e':
cout << "Number: ";
cin >> inNum;
if (inNum < 100 && inNum > -2)
*(solution + getPos(col,row)) = inNum;
else
{
for (int i = 0; i < 59; i++)
cout << "\n";
cout << "Must be a number -1 or greater with 1 or 2 digits.\n\n";
system("PAUSE");
}
break;
/////////////////////
case 'q':
break;
/////////////////////
default:
break;
/////////////////////
} // end 'switch'


if (in == 'q')
{
    count = 0;
    for (int i = 0; i < 144; i++)
    {
        if (solution[i] == -1)
        count++;
    } // end 'for'
    if (count > 1)
    {
        for (int i = 0; i < 59; i++)
        cout << "\n";
        cout << "There's more than one open spot.\n\n";
        system("PAUSE");
    }
    if (count == 0)
    {
        for (int i = 0; i < 59; i++)
        cout << "\n";
        cout << "There's no open spot.\n\n";
        system("PAUSE");
    }
    if (count == 1)
    break;
} // end 'if'


} // end input loop
} // end custom()




int* fn0()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 4, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 7, 8,-1, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn1()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0,
              0, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0,
              0, 9, 10,11,12,0, 0, 0, 0, 0, 0, 0,
              0, 13,14,15,-1,0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn2()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0,
              0, 6, 7, 8, 9,10, 0, 0, 0, 0, 0, 0,
              0, 11,12,13,12,15,0, 0, 0, 0, 0, 0,
              0, 16,17,18,19,20,0, 0, 0, 0, 0, 0,
              0, 21,22,23,24,-1,0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn3()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 1, 2, 3, 4, 5, 6, 0, 0, 0, 0, 0,
              0, 7, 8, 9, 10,11,12,0, 0, 0, 0, 0,
              0, 13,14,15,16,17,18,0, 0, 0, 0, 0,
              0, 19,20,21,22,23,24,0, 0, 0, 0, 0,
              0, 25,26,27,28,29,30,0, 0, 0, 0, 0,
              0, 31,32,33,34,35,-1,0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn4()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0,
              0, 8, 9,10,11,12,13,14, 0, 0, 0, 0,
              0, 15,16,17,18,19,20,21,0, 0, 0, 0,
              0, 22,23,24,25,26,27,28,0, 0, 0, 0,
              0, 29,30,31,32,33,34,35,0, 0, 0, 0,
              0, 36,37,38,39,40,41,42,0, 0, 0, 0,
              0, 43,44,45,46,47,48,-1,0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn5()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0,
              0, 9,10,11,12,13,14,15,16, 0, 0, 0,
              0, 17,18,19,20,21,22,23,24,0, 0, 0,
              0, 25,26,27,28,29,30,31,32,0, 0, 0,
              0, 33,34,35,36,37,38,39,40,0, 0, 0,
              0, 41,42,43,44,45,46,47,48,0, 0, 0,
              0, 49,50,51,52,53,54,55,56,0, 0, 0,
              0, 57,58,59,60,61,62,63,64,-1,0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn6()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0,
              0,10,11,12,13,14,15,16,17,18, 0, 0,
              0,19,20,21,22,23,24,25,26,27, 0, 0,
              0,28,29,30,31,32,33,34,35,36, 0, 0,
              0,37,38,39,40,41,42,43,44,45, 0, 0,
              0,46,47,48,49,50,51,52,53,54, 0, 0,
              0,55,56,57,58,59,60,61,62,63, 0, 0,
              0,64,65,66,67,68,69,70,71,72, 0, 0,
              0,73,74,75,76,77,78,79,80,-1, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn7()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 0,
              0,11,12,13,14,15,16,17,18,19,20, 0,
              0,21,22,23,24,25,26,27,28,29,30, 0,
              0,31,32,33,34,35,36,37,38,39,40, 0,
              0,41,42,43,44,45,46,47,48,49,50, 0,
              0,51,52,53,54,55,56,57,58,59,60, 0,
              0,61,62,63,64,65,66,67,68,69,70, 0,
              0,71,72,73,74,75,76,77,78,79,80, 0,
              0,81,82,83,84,85,86,87,88,89,90, 0,
              0,91,92,93,94,95,96,97,98,99,-1, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn8()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0,

Skimmed through your program, and it is not cout that seems to be the problem. You are calling cout too much. Remember that optimization of code should start first with your algorithm. The rest will usually be taken care by a decent compiler. Take for example the for loops where you are outputting 50 newline characters.

for ( i = 0 ; i < 50; i++ )
   cout << '\n';

This piece of code calls cout 50 times. IO functions take a lot of time. That means you are writting to the console 50 times which takes a lot of time, when you consider the total number of times you do this in your program.
A better way will be to first create the string with 50 newline characters and output them all in a single cout call. like this

std::string newline( 50, '\n');
    std::cout << newline ;

Clean up your code like that, and you will get to know more modifications where you can make the code fast.

thanks. I don't know how to apply it, though.... Im new. I dont even know what std:: and that newline function do. (sry)

newline is not a function. It is a string object. What std::string newline( 50, '\n' ) does is, create a string called newline that has 50, '\n' characters. Since you have used using namespace std; at the beginning, you can just use string newline(50, '\n' ); . You will have to use the #include <string> at the beginning. Then cout just outputs it. I suggest you get a good C++ book if you dont have one, and start reading about C++ strings to learn more. you may fine good tutorials in the internet too.

It's not a good idea to write a GUI in the console window.
You can do it of course, but you'll run into all sorts of problems.

If you have a java enabled browser this may give you some ideas as well.

Thanks again. Very much.

btw, have u tried compiling it?
I'm very proud of my primitive program ;)

Thanks again. Very much.

btw, have u tried compiling it?
I'm very proud of my primitive program ;)

Well I compiled it, and ran it. Hate to say it but it sucks. There are too many user options to set, and too many controls to memorize. For example I saw the keys to move items only at the start. After the game starts I do not see it. Having a very short term memory, I could only remember that pressing w moves the item above the space down. So naturally I closed the game at that point.

But overall I think the effort is good. And I think you should be proud about your program too. Brush up the rusty patches, mentioned in my above posts. Concentrate on how to make the instructions more userfriendly. Don't go into GUI programming in C/C++ yet. Learn the language first. Otherwise you will fall in a lot of trouble.

int* fn0()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 4, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 7, 8,-1, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}

Results in
$ g++ -W -Wall -ansi -pedantic -O2 15puzzle.cpp
15puzzle.cpp: In function ‘int* fn0()’:
15puzzle.cpp:278: warning: address of local variable ‘solution’ returned
For every function down to fnX()
When the function exits, the array no longer exists, so your pointer is invalid.
If it works for you, it is nothing more than luck - all I get is a segmentation fault.

Also, I get
15puzzle.cpp: At global scope:
15puzzle.cpp:723: warning: unused parameter ‘nNumberofArgs’
15puzzle.cpp:723: warning: unused parameter ‘pszArgs’
If you're not going to use the parameters, then just do
int main ( )

15puzzle.cpp: In function ‘void move(int, int*)’:
15puzzle.cpp:65: warning: ‘row’ may be used uninitialized in this function
15puzzle.cpp:65: warning: ‘col’ may be used uninitialized in this function
If the uninitialised value gets used, all sorts of chaos can happen.
Ensure the variables are initialised to something sensible before trying to use them.

Two more points
1. Using goto in that manner is a very poor substitute for a while loop.
2. A consistent approach to indentation will greatly assist you (and people who help you).

Thanks again. This is my slightly edited version, with string newline(59, '\n') . It is definitely faster. I didn't know what to do about the controls, though. All you need to know is that w, a, s and d move around. They're conveniently in the same shape as the arrow keys. I have no clue how to sort of getkey like basic, i can only input chars for now. And c at any time brings the controls back up. But this is my first non-trivial program. First one over maybe 50 lines that's more than a test of a feature.

Attachments
//
//
//           15 PUZZLE
//
//
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <time.h>
#include <string>
using namespace std;




int getCol(int pos)
{return pos%12;}

int getRow(int pos)
{return (int)(pos/12);}

int getPos(int col, int row)
{return row*12 + col;}




void dispPuz(int* current)
{
for (int i = 0; i < 144; i++)
{

if (*(current+i) == 0)
cout << "  ";
else
{
    if (*(current+i) == -1)
    cout << "--";
    else
    {
        if (*(current+i) == -2)
        cout << "?";
        else
        cout << *(current+i);
        
        if (*(current+i) < 10)
        cout << " ";
    } // end 'else'
    
    
    
} // end 'else'

cout << "   ";

if (getCol(i) == 11)
cout << "\n\n\n";
} // end 'for'
} // end dispPuz()




void move(int direction, int current[])
{
int row,col;

for (int i = 0; i < 144; i++)
{
if (current[i] == -1)
{
col = getCol(i);
row = getRow(i);
break;
} // end 'if'
} // end 'for'

if (direction == 1 && current[ getPos(col,row-1) ] != 0)
{
current[ getPos(col,row)] = current[ getPos(col,row-1)];
current[ getPos(col,row-1)] = -1;
} // end  up 'if'

if (direction == 2 && current[ getPos(col-1,row) ] != 0)
{
current[ getPos(col,row)] = current[ getPos(col-1,row)];
current[ getPos(col-1,row)] = -1;
} // end  left 'if'

if (direction == 3 && current[ getPos(col,row+1) ] != 0)
{
current[ getPos(col,row)] = current[ getPos(col,row+1)];
current[ getPos(col,row+1)] = -1;
} // end  down 'if'

if (direction == 4 && current[ getPos(col+1,row) ] != 0)
{
current[ getPos(col,row)] = current[ getPos(col+1,row)];
current[ getPos(col+1,row)] = -1;
} // end  right 'if'
} // end move()




int testWin(int current[], int solution[])
{
int win = 0;
int i;
for (i = 0; i < 144; i++)
{
if (current[i] != solution[i])
break;
} // end 'for'

if (i == 144)
win = 1;
return win;
} // end testWin()




void scramble(int current[])
{
srand(time(NULL));
for (int i = 0; i < 1000000; i++)
move(rand()%4+1, current);
} // end scramble()




void dispControls()
{
string newline(59, '\n');
cout << newline;

cout << "CONTROLS\n\nQ   E\n\n  Z X C\n\nC - Display Controls\nE - Display "
<< "Solution\nZ - Scramble\nX - Solve (Not done yet)\nQ - Quit to Menu\n\n  "
<< "W\n A S D\n\nW - Move the number above the space down\nA - Move the number "
<< "to the left of the space right\nS - Move the number below the space "
<< "up\nD - Move the number to the right of the space left\n\n-You can put in "
<< "a sequence of letters.\n-Make sure Caps Lock is off.\n\n";
system("PAUSE");
} // end dispControls()




void dispControls2()
{
string newline(59, '\n');
cout << newline;

cout << "CONTROLS\n\nQ   E\n\n      C\n\nC - Display Controls\nE - Change "
<< "the block\nQ - End customize\n\n  W\n A S D\n\nW - Move cursor up\nA - "
<< "Move cursor left\nS - Move cursor down\nD - Move cursor right\n\n-You "
<< "can put in a sequence of letters.\n-Make sure Caps Lock is off.\n\nCHANGING "
<< "THE BLOCK\n\n0  - Unused block\n#  - A sliding block\n-1 - The empty "
<< "space\n\n";
system("PAUSE");
} // end dispControls2()




void custom(int* solution)
{
string newline(59, '\n');

int row = 1;
int col = 1;
char in;
int inNum, count;

int solution2[144];
for (int i = 0; i < 144; i++)
*(solution+i) = 0;

dispControls2();

for (;;) // input loop
{

cout << newline;

for (int i = 0; i < 144; i++)
solution2[i] = *(solution+i);
solution2[getPos(col,row)] = -2;
dispPuz(solution2);

cout << "Choice: ";
cin >> in;

switch (in)
{
/////////////////////
case 'w':
if (row != 1)
row--;
break;
/////////////////////
case 'a':
if (col != 1)
col--;
break;
/////////////////////
case 's':
if (row != 10)
row++;
break;
/////////////////////
case 'd':
if (col != 10)
col++;
break;
/////////////////////
case 'c':
dispControls2();
break;
/////////////////////
case 'e':
cout << "Number: ";
cin >> inNum;
if (inNum < 100 && inNum > -2)
*(solution + getPos(col,row)) = inNum;
else
{
cout << newline;
cout << "Must be a number -1 or greater with 1 or 2 digits.\n\n";
system("PAUSE");
}
break;
/////////////////////
case 'q':
break;
/////////////////////
default:
break;
/////////////////////
} // end 'switch'


if (in == 'q')
{
    count = 0;
    for (int i = 0; i < 144; i++)
    {
        if (solution[i] == -1)
        count++;
    } // end 'for'
    if (count > 1)
    {
        cout << newline;
        cout << "There's more than one open spot.\n\n";
        system("PAUSE");
    }
    if (count == 0)
    {
        cout << newline;
        cout << "There's no open spot.\n\n";
        system("PAUSE");
    }
    if (count == 1)
    break;
} // end 'if'


} // end input loop
} // end custom()




int* fn0()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 4, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 7, 8,-1, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn1()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0,
              0, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0,
              0, 9, 10,11,12,0, 0, 0, 0, 0, 0, 0,
              0, 13,14,15,-1,0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn2()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0,
              0, 6, 7, 8, 9,10, 0, 0, 0, 0, 0, 0,
              0, 11,12,13,12,15,0, 0, 0, 0, 0, 0,
              0, 16,17,18,19,20,0, 0, 0, 0, 0, 0,
              0, 21,22,23,24,-1,0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn3()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 1, 2, 3, 4, 5, 6, 0, 0, 0, 0, 0,
              0, 7, 8, 9, 10,11,12,0, 0, 0, 0, 0,
              0, 13,14,15,16,17,18,0, 0, 0, 0, 0,
              0, 19,20,21,22,23,24,0, 0, 0, 0, 0,
              0, 25,26,27,28,29,30,0, 0, 0, 0, 0,
              0, 31,32,33,34,35,-1,0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn4()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0,
              0, 8, 9,10,11,12,13,14, 0, 0, 0, 0,
              0, 15,16,17,18,19,20,21,0, 0, 0, 0,
              0, 22,23,24,25,26,27,28,0, 0, 0, 0,
              0, 29,30,31,32,33,34,35,0, 0, 0, 0,
              0, 36,37,38,39,40,41,42,0, 0, 0, 0,
              0, 43,44,45,46,47,48,-1,0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn5()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0,
              0, 9,10,11,12,13,14,15,16, 0, 0, 0,
              0, 17,18,19,20,21,22,23,24,0, 0, 0,
              0, 25,26,27,28,29,30,31,32,0, 0, 0,
              0, 33,34,35,36,37,38,39,40,0, 0, 0,
              0, 41,42,43,44,45,46,47,48,0, 0, 0,
              0, 49,50,51,52,53,54,55,56,0, 0, 0,
              0, 57,58,59,60,61,62,63,64,-1,0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn6()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0,
              0,10,11,12,13,14,15,16,17,18, 0, 0,
              0,19,20,21,22,23,24,25,26,27, 0, 0,
              0,28,29,30,31,32,33,34,35,36, 0, 0,
              0,37,38,39,40,41,42,43,44,45, 0, 0,
              0,46,47,48,49,50,51,52,53,54, 0, 0,
              0,55,56,57,58,59,60,61,62,63, 0, 0,
              0,64,65,66,67,68,69,70,71,72, 0, 0,
              0,73,74,75,76,77,78,79,80,-1, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn7()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 0,
              0,11,12,13,14,15,16,17,18,19,20, 0,
              0,21,22,23,24,25,26,27,28,29,30, 0,
              0,31,32,33,34,35,36,37,38,39,40, 0,
              0,41,42,43,44,45,46,47,48,49,50, 0,
              0,51,52,53,54,55,56,57,58,59,60, 0,
              0,61,62,63,64,65,66,67,68,69,70, 0,
              0,71,72,73,74,75,76,77,78,79,80, 0,
              0,81,82,83,84,85,86,87,88,89,90, 0,
              0,91,92,93,94,95,96,97,98,99,-1, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn8()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0

Guess im lucky.:) I have the same warnings, but no actual compile errors. Again again thank you, I'm learning alot. I'm used to gotos from basic, i know theyre obsolete in C++. It was easier for me at the time, and really big loops are confusing to me. :confused: I will try.

Sry for my repeat posts, but i had a problem, and this was my solution. Like Salem said, it was lucky. I couldn't figure out how to store values to an array with {1,2,3....} unless it's being initialized. Obviously, the {1,2,3....} is the only practical way (that i know of) to store all the data in the arrays. I couldn't use conditions to only declare and initialize the array to a certain set of numbers, because even though it would only be declared once, the compiler errors and says im redeclaring as I have multiple declarations of the same variable in the same scope. So I made functions to do it and return a pointer to the array, so it wouldn't error because they all declare the array in a different scope. Not that it would matter if i gave 'solution' a different name in each function. It was faulty logic I know, but it seemed like an answer and it works. I also know now that the array is technically garbage data and goes out of scope when the function returns, and that any new variable could potentially mess with the array. I would like suggestions of better ways to store the info in the array. Also, the row & col should be initialised your right (just to 0 or something right?). I don't use them without storing something first, but what i store in them at first isn't constant.

> Guess im lucky. I have the same warnings, but no actual compile errors.
It is very difficult for newbies to tell which warnings are important, and which can be ignored. So you should really be fixing the ones you can fix, and asking questions about those you can't understand the reason for.

Even pros should be aiming for zero warnings as well.

> I would like suggestions of better ways to store the info in the array.
Voila

void getSolution ( int which, int *solution ) {
  static int solutions[][144] = {
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 4, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 7, 8,-1, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0,
      0, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0,
      0, 9, 10,11,12,0, 0, 0, 0, 0, 0, 0,
      0, 13,14,15,-1,0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
    /* Add more here */
  };
  int i;
  for ( i = 0 ; i < 144 ; i++ ) {
    solution[i] = solutions[which][i];
  }
}

In main, rather than having just a pointer, you would replace this

int current[144];
for (int i = 0; i < 144; i++)
current[i] = *(solution+i);

With this code, which would store the answer directly into the array you wanted it, without you having to do the copy in main (because the copy is now inside the called function).

case '0':
getSolution( 0, current );
break;
case '1':
getSolution( 1, current );
break;
case '2':
getSolution( 2, current );
break;

Perhaps prompt the user for a solution number rather than a solution letter, then you can remove the entire switch case with

int which;
cout << "Which one?";
cin >> which;
getSolution( which, current );

Thanks. I didnt think to use a matrix like that, so that i dont have to reference every solution individually, i can reference by number (which is sortof what i was looking for to begin with). I wouldn't need getSolution as a function, would I? Since it would only be called once in the program (or atleast only typed once)? Unless it has something to do with static? What does static do? Is it possible to return an array in a function, or only its pointer? And I still would like to know (even though i have no immediate need now) if its possible to store an array with {1,3,6,2....} while not initialising it. Tell me if i'm wrong, but i think i've noticed that you can use either an array or a pointer as an argument (they'd be used differently in the function, of course), and then you can pass either an array or a pointer and it will convert it according to the argument type.

I would like an answer...
I know they seem unrelated, but all these questions have come up from my 15 puzzle program (first program) and are probably simple to most people.

Thanks. I didnt think to use a matrix like that, so that i dont have to reference every solution individually, i can reference by number (which is sortof what i was looking for to begin with). I wouldn't need getSolution as a function, would I? Since it would only be called once in the program (or atleast only typed once)?

Use the function. It's modular and better programming practice.

Unless it has something to do with static?

Nope.

What does static do?

When used with a variable in a function, each time the function is entered the variable retains the value from the last time the function was used.

Is it possible to return an array in a function, or only its pointer?

Pointer...

And I still would like to know (even though i have no immediate need now) if its possible to store an array with {1,3,6,2....} while not initialising it.

Not a clue what you are asking. In order to get the values in the array it must be initialized somehow.

So how can i write a GUI in C++ without the console window?

To use GUI you should first learn Win32 API and/or MFC.
I suggest you learn C++ throughout in the first place.

This article has been dead for over six months. Start a new discussion instead.