Well i compiled the program and it seems to work just fine.
Are you sure, that the program crashes if INput is >4?
Sky Diploma
Practically a Posting Shark
865 posts since Mar 2008
Reputation Points: 673
Solved Threads: 131
Try to use char variable of choice. Then your code will be like this
//declaration
void decision(char action);
//implementation
void decision(char action) { // Are these variable & function names acceptable?
string word;
switch (action) {
case '1':
cout << "\nEnter word: \n" << flush;
cin >> word;
to_lower(word);
if (binarySearch(words,word,0,nWord)) {
cout << word << " is in the dictionary\n";
}
else
cout << word << " is NOT in the dictionary\n";
break;
case '2':
cout << "\nEnter word pattern with ? for missing letters\n" << flush;
cin >> word;
to_lower(word);
search(words,nWord,word);
break;
case '3':
// I dont think I need to put anything here because break will stop the function then main will return 0
//system("pause");
//return 0;
break;
default:
cout << "Invalid Choice";
break;
}
}
And main
int main()
{
char option;
// loop to display menu, get user choice and perform required action
while(option != '3') {
printMenu();
cin >> option; // if I type anything other than 1,2,3 the program works correctly
decision(option);
}
//system("pause");
return 0;
}
P.S. Also you can use getchar() or cin.get(), or _getche() mothod to get the char choice.
I hope it will help you.
Protuberance
Junior Poster in Training
90 posts since Aug 2009
Reputation Points: 78
Solved Threads: 17
use stringstream. Convert string to numerics. To avoid all the integer
hassle.
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608