Я вычислил часть деления и сокращения диапазона, но теперь моя программа не закроется...
using System; namespace Rinse_and_Repeat { class Program { static void Main(string[] args) { string version = "1.2.0"; string title = "Age Guesser"; string author = "Tenet"; int age; int tries = 0; int maxTries = 3; int guesses = 0; int totalGuesses = 0; int rangeHigh = 100; int rangeLow = 0; Console.WriteLine("Welcome to {0}! Version: {1} Author: {2}", title, version, author); while (true) { Console.WriteLine($"Tries: {tries} | Please input your age: "); var ageString = Console.ReadLine(); if (Int32.TryParse(ageString, out age)) { if (age <= 100 && age >= 0) { Console.WriteLine("Is this right: Y/N: " + age); if (Console.ReadKey().Key == ConsoleKey.Y) { Console.Clear(); break; } } else Console.WriteLine("You are either too old to be alive or too young to be playing this game"); } if (++tries > maxTries) break; } Random random = new Random(); while (true) { int guess = random.Next(rangeLow, rangeHigh); Console.WriteLine("Is my guess too high(Up Arrow), too low(Down Arrow), or perfect(P)?: " + guess); //trying to make it so if the rangeHigh is evenly divisiable it will divide it but if it isn't then it will just round down to the closest number if (Console.ReadKey().Key == ConsoleKey.UpArrow) { if (rangeHigh % 2 == 0) { rangeHigh = rangeHigh / 2; } else { --rangeHigh; rangeHigh = rangeHigh / 2; } } //If they say the guess is too low, it multiplies the low range by 2 else if (Console.ReadKey().Key == ConsoleKey.DownArrow) { rangeLow = rangeLow * 2; } //It just stops the program if the computer gets the guess right else if (Console.ReadKey().Key == ConsoleKey.P) { Console.WriteLine("Yay I got it!"); break; } } } } }
Что я уже пробовал:
//It just stops the program if the computer gets the guess right else (Console.ReadKey().Key == ConsoleKey.P) { Console.WriteLine("Yay I got it!"); break; }
Tenet1001
Правка: МММ. Так что это вроде как работает...Мне просто нужно нажать клавишу "Р" 3 раза, чтобы она заработала, и я также сгладил еще несколько ошибок.