I'm writing a command-line tic-tac-toe game and i've encountered a problem in my helpMenu() function, whenever i recursively call the function with an argument, the cin.get() pause ceases to work. Any help appreciated, thanks.
The following is my test.cpp file, whenever i write some new function i always put it in a separate file first until i get it working exactly the way i want it to, then i place it in my main.cpp file.
#include <iostream>
#include <stdlib.h>
#ifdef _WIN32
#define CMD_CLEAR "cls"
#endif
#ifdef linux
#define CMD_CLEAR "clear"
#endif
using namespace std;
int helpMenu(int choice = 0);
int main() {
helpMenu();
return 0;
}
int helpMenu(int hM_choice) {
if (hM_choice != 0) {
// Argument specified.
if ((hM_choice >= 1) && (hM_choice <= 3)) {
system(CMD_CLEAR);
cout << "\n\n\n\t\t\t";
if (hM_choice == 1) {
cout << "[ How to Play ]\n\n";
cout << "\tThe aim of the game is to build a 5-in-a-row line across\n";
cout << "\tthe grid in any direction before your opponent. This is\n";
cout << "\tthe only way to win the game.\n\n";
} else if (hM_choice == 2) {
cout << "[ About ]\n\n";
cout << "\tThis game was created for educational purposes by Exussum.\n\n";
cout << "\tE-mail: exussum@gmx.com\n\n";
} else { return 0; }
cout << "\n\n\n Hit the return key to continue..\n";
cin.get();
}
else { helpMenu(); }
}
else {
// No argument, display help menu.
string hM_menuChoice;
system(CMD_CLEAR);
cout << "\n\n\n\t1) How To Play.\n\t2) About.\n\n\t3) Close Help Menu.\n ";
cin >> hM_menuChoice;
if (hM_menuChoice.length() == 1) {
if (hM_menuChoice[0] == '1') { helpMenu(1); }
else if (hM_menuChoice[0] == '2') { helpMenu(2); }
else { helpMenu(3); }
}
else {
system(CMD_CLEAR);
cout << "\n\n\n\n\n\t\t";
cout << "Invalid menu choice." << ".\n\n\n\n";
sleep(2); helpMenu();
}
helpMenu(2);
}
return 0;
}