I'm developing a c++ dictionary and I made a map of functions to search for words.
The program prompts the user to choose "search for a word" or "add a new word".
The problem: I made a map of functions that will be called if the user chooses to search for a word, but the program doesn't seem to be calling the function.
I'm new to map
and haven't used it before today, some help would be great.
#include <iostream>
#include <map>
using namespace std;
//map of function to search for word
map <string, int> search_word(map<string, int> &word_bank, int val)
{
string word;
cout<<"Search word: "<<endl;
cin>>word;
if(word_bank.find(word) != word_bank.end())
cout<<word<<endl;
else if (word_bank.find(word) == word_bank.end())
cout<<"word not found";
}
int main()
{
int choice;
map <string, int> word_bank;
word_bank["diingati"] = 0;
word_bank["diperbuat"] = 1;
word_bank["keibuan"] = 2;
word_bank["kepercayaan"] = 3;
word_bank["menggunakan"] = 4;
word_bank["mempergunakan"] = 5;
cout<<"***"<<" Welcome to C++ Malay Dictionary "<<"***"<<endl<<endl;
cout<<"Do you want to search for a word or enter a new word? "<<endl<<endl;
cout<<"Search : 1"<<endl<<"Enter new word: 2"<<endl<<endl;
cin>>choice;
if (choice == 1)
map <string, int> search_word; //calling the function
else
cout<<"Please enter a number: ";
cin>>choice;
}