0

Hello programmers!

I am making a player vs. computer Tic-Tac-Toe game in xCode that is a class, with its run() method as its only public member function apart from the initializer. I want to decide whether the player goes first, and I created a function to do that called determineFirst(). This function depends on another one called askYesNoQuestion(const std::string& question) to actually question the player as to him/her going first. My code is below:

bool determineFirst()
{
    //ask player if he wants to play
    static const string question="Do you want to play a game of Tic-Tac-Toe?";
    return askYesNoQuestion(question);
}



bool askYesNoQuestion(const std::string& question)
{
    static char ans;

    //ask question
    std::cout << question << " (yes/no): ";
    std::cin.get(ans);
    std::cout << std::endl;

    //check if the answer is satisfactory (first letter of response only)
    if((toupper(ans)!='N')||(toupper(ans)!='Y'))
    {
        std::cout << "That is not a valid answer to the question"<< std::endl;
        bool yes=askYesNoQuestion(question);
        return yes;
    }
    else
    {
        return toupper(ans)=='Y';
    }
}

However, my xCode editor states that there is "No matching function for call to 'askYesNoQuestion'". This message is showing up on the return statement of determineFirst(). What seems to be the problem

2
Contributors
4
Replies
12
Views
3 Years
Discussion Span
Last Post by nathan.pavlovsky
0

Did you prototype the functin askYesNoQuestion() at the beginning of your program so that the compiler knows about it?

line 20: It would be better to just set another variable to be toupper(ans) so that toupper() isn't called every time it is used.

Edited by Ancient Dragon

0

Are you saying those two functions are members of a c++ class? If yes, then you need to add class decoration to them, for example if the class name is MyClass then line 1 of the code you posted would be

bool MyClass::determineFirst()

and line 20

bool MyClass::askYesNoQuestion(const std::string& question)

Edited by Ancient Dragon

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.