Hi all, I am writing a program to make a binary tree. I have all the class/structure part fine, I just want to make the program unbreakable. I am asking the user to input strings, and I am putting those strings into the tree as all lower case (I also have this done as well). What I wanted to know is how would I make sure that they input a qualifying string. If they insert like numbers, for example, to display that it is bad data, and ask them to try again... I tried this, but it didn't work.
void add_node(Tree tree, int count)
{
char again;
string word;
cout << "Please enter a word: ";
cin >> word;
if (cin.fail())
{
cin.clear();
cout << "Not a valid input for the Binary Tree Mister!" << endl;
add_node(tree, count);
}
to_lower(word);
if (count == 0)
{
tree.add(word);
count++;
}
else
{
tree.add(tree.get_root(), word);
}
cout << "Would you like to enter another word?";
cin >> again;
tolower(again);
if (again == 'y')
{
add_node(tree, count);
}
else
{
Menu(tree, count);
}
}