/// <summary> /// Allows you to ask a question until you get an acceptable answer /// </summary> /// <param name="question">The question you wish to ask (Single line version)</param> /// <returns></returns> public static BaseAnswer AskQuestion(string question, BaseAnswer [] acceptedAnswers) { return AskQuestion(new string[] { question }, acceptedAnswers); }
/// <summary> /// Allows you to ask a question until you get an acceptable answer /// </summary> /// <param name="question">The question you wish to ask (Multiple line version)</param> /// <returns></returns> public static BaseAnswer AskQuestion(string[] question, BaseAnswer[] acceptedAnswers) { int i = 0; do { foreach(string qString in question) Console.WriteLine(qString); //Print out the question/repeat it if we don't accept the user's answer string input = Console.ReadLine(); for(i = 0; i < acceptedAnswers.Length; i++) { if(acceptedAnswers[i].Answer == input) break; } } while(acceptedAnswers.Length == i); return acceptedAnswers[i]; }