< Previous | Contents | Next >

The askYesNo() Function

This function asks a yes or no question. It keeps asking the question until the player enters either a y or an n. It receives a question and returns either a ’y’ or an ’n’.

Introducing the Tic-Tac-Toe Game 209



char askYesNo(string question)

{

char response; do

{

cout << question << " (y/n): "; cin >> response;

} while (response != ’y’ && response != ’n’);


return response;

}