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).
[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