#include #include #include #include #include #include using namespace std; string GoodPhrase(int n); string BadPhrase(int n); string VaguePhrase(int n); void PrintResponse(int n ,boost::function answer); int main() { string question; int answer; boost::mt19937 rng(time(NULL)); boost::uniform_int<> dist(0,19); boost::variate_generator > result(rng,dist); while(1) { cout << endl; cout << "Enter a question for the might eight ball =>"; getline(cin, question); answer = result(); if (answer < 10) { PrintResponse(answer, GoodPhrase); } else if (answer < 15) { PrintResponse(answer-10,BadPhrase); } else { PrintResponse(answer-15,VaguePhrase); } } } void PrintResponse(int n ,boost::function answer){ cout << "*******************************************" << endl; cout << "* The magic eight ball responds with * " << endl; cout << "\t\t" << answer(n) << endl;; cout << "* And thus it was spoken. *" << endl; cout << "*******************************************" << endl; } string GoodPhrase(int n) { switch(n) { case 0: return "It is certain"; case 1: return "It is decidedly so"; case 2: return "Without a doubt"; case 3: return "Yes definitely"; case 4: return "You may rely on it"; case 5: return "As I see it yes"; case 6: return "Most likely"; case 7: return "Outlook good"; case 8: return "Yes"; case 9: return "Signs point to yes"; default: return "Yep"; } } string VaguePhrase(int n){ switch(n) { case 0: return "Reply hazy try again"; case 1: return "Ask again later"; case 2: return "Better not tell you now"; case 3: return "Cannot predict now"; default: return "Concentrate and ask again"; } } string BadPhrase(int n){ switch(n) { case 0: return "Reply hazy try again"; case 1: return "Ask again later"; case 2: return "Better not tell you now"; case 3: return "Cannot predict now"; default: return "Concentrate and ask again"; } }