gpt-4-0314· OpenAI
WildChat-4.8M (AI2)
Program the following Instructions with simple functional C# Code: Implement the…
- User
Program the following Instructions with simple functional C# Code: Implement the guessing game with a menu system. The resting of the magic number should not be acknowledged, but not displayed. The user has to guess a number between 1-10. Have the Play make a single guess with "low" or "high" or "correct" messaging. After a guess, go back to the main menu.
Guessing game
- Reset magic number
- Play
- Quit Enter choice:
Example output: Guessing game
- Reset magic number
- Play
- Quit Enter choice: 1 Magic number reset
Guessing game
- Reset magic number
- Play
- Quit Enter choice: 2 Enter guess (1-10): 4 low
Guessing game
- Reset magic number
- Play
- Quit Enter choice: 3 bye
- Assistant
using System; namespace GuessingGame { class Program { static int magicNumber; static void Main(string[] args) { while (true) { Console.WriteLine("Guessing game"); Console.WriteLine("1. Reset magic number"); Console.WriteLine("2. Play"); Console.WriteLine("3. Quit"); Console.Write("Enter choice: "); int choice = int.Parse(Console.ReadLine()); if (choice == 1) { ResetMagicNumber(); } else if (choice == 2) { PlayGame(); } else if (choice == 3) { Console.WriteLine("bye"); break; } } } static void ResetMagicNumber() { Random random = new Random(); magicNumber = random.Next(1, 11); Console.WriteLine("Magic number reset\n"); } static void PlayGame() { if (magicNumber == 0) ResetMagicNumber(); Console.Write("Enter guess (1-10): "); int guess = int.Parse(Console.ReadLine()); if (guess == magicNumber) { Console.WriteLine("correct\n"); } else if (guess < magicNumber) { Console.WriteLine("low\n"); } else { Console.WriteLine("high\n"); } } } }