In my code, I'm trying to get char* Humanturn to point to the return value of the AskYesorNo function. I return the address of some global const chars, but get a compile error on these return addresses. A little help please. :)
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
//function prototypes
void DisplayInstructions();
char GetHumanTurn();
char* AskYesorNo(string question);
//constant characters
const char EMPTY = ' ';
const char X = 'X';
const char O = 'O';
int main()
{
DisplayInstructions();
vector<char> board(8, EMPTY);
char Human = (GetHumanTurn());
//testing purposes
cout << endl << Human;
system("PAUSE");
return 0;
}
void DisplayInstructions()
{
cout << "Welcome to Tic Tac Toe! \nWhere you will test your might against man's greatest creation, the computer!\nBe prepared to go one on one with the processor as you battle for supremacy,\nand the entire human race!" << endl;
cout << "The rules are simple, pick a number that corresponds with the position on the \nboard.\n\nExample board:\n\n";
cout << "| 0 | - - | 1 | - - | 2 |\n\n| 3 | - - | 4 | - - | 5 |\n\n| 6 | - - | 7 | - - | 8 |" << endl;
}
char GetHumanTurn()
{
char* HumanTurn = AskYesorNo("\nDo you want to go first? (y or n)");
if(*HumanTurn == X)
{
return X;
}
else
{
return O;
}
}
char* AskYesorNo(string question)
{
char answer;
cout << endl;
do
{
cout << question;
cin >> answer;
}
while(answer != 'y' && answer != 'n');
if(answer == 'y')
{
return &X;
}
if(answer == 'n')
{
return &O;
}
}
E:\Documents and Settings\Kev\Desktop\Book Exercizes\tictactoewithpntrs.cpp In function `char* AskYesorNo(std::string)':
61 E:\Documents and Settings\Kev\Desktop\Book Exercizes\tictactoewithpntrs.cpp invalid conversion from `const char*' to `char*'
65 E:\Documents and Settings\Kev\Desktop\Book Exercizes\tictactoewithpntrs.cpp invalid conversion from `const char*' to `char*'