ID:182072
 
Would anyone mind explaining what I'm doing wrong? I'm getting the errors:

error C3861: 'turn2text': identifier not found
error C3861: 'CheckWin': identifier not found
error C2065: 'end1' : undeclared identifier
error C2065: 'end1' : undeclared identifier


The end1 errors strike me as odd. It was used in a snippet in the tutorial I'm reading without any prior definition. The other two errors also strike me as odd, assuming that identifier means that I hadn't declared the function prior to calling it (I have a header file containing all my functions).

Here's my header with all my functions:
void DispMap()
void Init()
int TakeInput()
char turn2text()
void CheckWin()


and here is my source:

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

bool turn = 0;
bool finished;
int map[3][3];
int nmap[3][3];

void DispMap()
{
int x, y;
string Output = "Map" + '\n';
for(x = 0; x <= 3; x++)
{
for(y = 0; y <= 3; y++)
{
Output += map[x][y];
}
Output += '\n';
}
}

int TakeInput()
{
turn = !turn;
cout << "Player " << turn+1 << "'s turn!" << endl;
int x = -1;
int y = -1;
while(((x > 3 || x < 1) && (y > 3 || y < 1)) || !map[x][y] ) cin >> x >> y;
map[x][y] = turn2text();
nmap[x][y] = turn;
DispMap();
CheckWin();
return 1;
}


void Init() {}

void CheckWin() {}

char turn2text()
{
if(turn == 0) return 'X';
else return 'O';
}

int main()
{
cout << "Welcome to checkers! Please make your moves as x coord, y coord" << end1;
while(!finished) TakeInput();
cout << "Player " << turn+1 << " has won! Better luck next time, player " << (!turn)+1 << "!" << end1;
return 0;
}


It's rather procedural now, I haven't gotten to learning about objects in C++ yet. Anyone know what I'm doing wrong, or just how to improve the code in general (besides making it less procedural).
This si just a generally good thing to do in the first place and is the root of your problem. See, in your TakeInput function you use functions that the compiler doesn't know about yet. Basically, it has no idea what you are talking about. A good thing to do is just do prototypes before your main function and then implement them afterwards like so:

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

bool turn = 0;
bool finished;
int map[3][3];
int nmap[3][3];

void DispMap()
void Init()
int TakeInput()
char turn2text()
void CheckWin()


int main()
{
cout << "Welcome to checkers! Please make your moves as x coord, y coord" << end1;
while(!finished) TakeInput();
cout << "Player " << turn+1 << " has won! Better luck next time, player " << (!turn)+1 << "!" << end1;
return 0;
}

void DispMap()
{
int x, y;
string Output = "Map" + '\n';
for(x = 0; x <= 3; x++)
{
for(y = 0; y <= 3; y++)
{
Output += map[x][y];
}
Output += '\n';
}
}

int TakeInput()
{
turn = !turn;
cout << "Player " << turn+1 << "'s turn!" << endl;
int x = -1;
int y = -1;
while(((x > 3 || x < 1) && (y > 3 || y < 1)) || !map[x][y] ) cin >> x >> y;
map[x][y] = turn2text();
nmap[x][y] = turn;
DispMap();
CheckWin();
return 1;
}


void Init() {}

void CheckWin() {}

char turn2text()
{
if(turn == 0) return 'X';
else return 'O';
}


[Edit]
Oops, forgot the rest...

Basically now it (the compiler) knows that there are those functions and now you can use them even though you haven't stated the implementation yet. That's a good thing about C++ and C, you don't have to implement stuff right away most of the time.

Prototyping like that will also prepare you for C++ classes written properly.

George Gough
In response to KodeNerd
He had a good chunk of it right, but let me fix some errors (i.e. semicolons)

 #include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

bool turn = 0;
bool finished;
int map[3][3];
int nmap[3][3];

void DispMap();
void Init();
int TakeInput();
char turn2text();
void CheckWin();


int main()
{
cout << "Welcome to checkers! Please make your moves as x coord, y coord" << end1;
while(!finished) TakeInput();
cout << "Player " << turn+1 << " has won! Better luck next time, player " << (!turn)+1 << "!" << end1;
return 0;
}

void DispMap()
{
int x, y;
string Output = "Map" + '\n';
for(x = 0; x <= 3; x++)
{
for(y = 0; y <= 3; y++)
{
Output += map[x][y];
}
Output += '\n';
}
}

int TakeInput()
{
turn = !turn;
cout << "Player " << turn+1 << "'s turn!" << endl;
int x = -1;
int y = -1;
while(((x > 3 || x < 1) && (y > 3 || y < 1)) || !map[x][y] ) cin >> x >> y;
map[x][y] = turn2text();
nmap[x][y] = turn;
DispMap();
CheckWin();
return 1;
}


void Init() {}

void CheckWin() {}

char turn2text()
{
if(turn == 0) return 'X';
else return 'O';
}


This problem occurred because you attempted to call text2turn() in DispMap() before you actually declared text2turn(). By declaring these functions (without defining them) at the top, you can then call them from within each other, no matter the order. It is a good habbit to get into. For larger projects, the standard procedure is to put all the declarations (or prototyping) in a header file.
In response to Stupot
Oops, I knew I forgot something. I still make those mistakes even after all this time, it's embarrassing to be honest.

Also, Jeff, you said you did have a header file, at least from what I read. What you didn't do to make it work however is to include it; just because it is in the same project doesn't mean that it is going to be included into every file (which will turn out to be a good thing if you ever work on large projects).

George Gough
Also, it's "endl"(L) not "end1"(one), since they both look similar in this font.
In response to Oasho
Oh, thanks. The website I was looking at made them look exactly the same.
In response to KodeNerd
just because it is in the same project doesn't mean that it is going to be included into every file (which will turn out to be a good thing if you ever work on large projects).

Thanks, that's half the problem, by the sound of it (the other half is the endl thing). I did prototype my functions, but they were in the header!
In response to Jeff8500
Yep, just think of it as "endline". Alternatively, you can use the text macro "\n" for newlines.
In response to Airjoe
endl does have a few benefits in that it's cross-platform, useful when writing to files.
In response to Airjoe
I know, but it appears that it's better to get in the habit of using endl, judging by what I'm reading.

"The endl manipulator produces a newline character, exactly as the insertion of '\n' does, but it also has an additional behavior when it is used with buffered streams: the buffer is flushed".

I have no clue what a buffer is as of now, programming wise at least, but it sounds like I'll need to flush it!
In response to Jeff8500
Basically all the characters normally don't have to be displayed when you say to display them. Flushing the buffer forces that. Note, I haven't done console output in a long time but that should be right.

George Gough
In response to KodeNerd
Buffers don't have to be restricted to text handling. They are rather common when it comes down to networks and some other things as well ;)

You're right though, a buffer just "stores something while it's not urgently needed" in order to increase efficiency and thus performance when it is better to "output" a larger bunch of data at once. And flushing actually forces just that.