From fa5a5b1b2e0012e8f13dabbf924c536f4c102405 Mon Sep 17 00:00:00 2001 From: Tony Bark Date: Thu, 13 Mar 2025 10:05:02 -0400 Subject: [PATCH] Minor quality of life changes --- Program.cs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Program.cs b/Program.cs index 1d87019..c9c5fce 100644 --- a/Program.cs +++ b/Program.cs @@ -84,32 +84,35 @@ string SelectTopics(List topics) foreach (var topic in topics) { numOfTopics++; - topicDict.Add(numOfTopics, topic.Trim()); - userChoices.Add($"{numOfTopics} {topic.Trim()}"); + var title = topic.Trim(); + topicDict.Add(numOfTopics, title); + userChoices.Add($"{numOfTopics} {title}"); } var selection = string.Join(", ", userChoices.ToArray()); - Console.WriteLine($"Select a Topic (Choose a Number){Environment.NewLine}{selection}"); + Console.WriteLine($"{Environment.NewLine}Select a Topic (Choose a Number){Environment.NewLine}{selection}"); var input = Console.ReadLine(); - // + // Attempt to parse a number. if (int.TryParse(input, out topicNum) == true) topicChoice = topicDict[topicNum]; else - { - Console.Clear(); - Console.Write($"{Environment.NewLine}Try again."); - NewTopic(topics); - } + NewTopic(topics, false); return topicChoice; } +/// +/// Selects a new topic either by prompting the user or randomly choosing one from the list. +/// +/// A list of available topics. +/// Indicates whether to prompt the user again if no selection was made. +/// The selected topic as a string. string NewTopic(List topics, bool retry = false) { var newTopic = ""; - if (UserChoice("Choose a Topic?")) + if (UserChoice("Choose a Topic?") || retry) newTopic = SelectTopics(topics); else {