static void Main(string[] args)
Console.Title = "Information Application";
DisplayError($"An unexpected error occurred: {ex.Message}");
runAgain = PromptToContinue();
Console.WriteLine("\nThank you for using the application!");
static void RunApplication()
Console.WriteLine("Information Application!\n");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"\nHello, {name}! You are {age} years old.");
Console.Write("Please enter your name: ");
name = Console.ReadLine().Trim();
if (string.IsNullOrWhiteSpace(name))
DisplayError("Name cannot be empty. Please try again.\n");
} while (string.IsNullOrWhiteSpace(name));
Console.WriteLine("\nPlease enter your age:");
Console.Write("Age (0-150 years): ");
string input = Console.ReadLine();
isValid = int.TryParse(input, out age);
DisplayError("Invalid input. Please enter a whole number.\n");
else if (age < 0 || age > 150)
DisplayError("Age must be between 0 and 150. Please try again.\n");
static bool PromptToContinue()
Console.Write("\nWould you like to run the application again? (Y/N): ");
var response = Console.ReadLine().Trim().ToUpper();
return response == "Y" || response == "YES";
static void DisplayError(string message)
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Error: {message}");