static void HighLow() { var random = new Random(); var number = random.Next(1, 100); bool won = false; int guesses = 0; string message; while (!won) { message = "Guess a number between 1-99: "; int input = Ex01.ReadInt(message); if (input == number) { guesses++; message = "That is correct. It took only: " + guesses; Console.WriteLine(message); won = true; break; } if (input < 1 || input >= 100) { message = "Number is outside current game range. Try again"; Console.WriteLine(message); } if (input < number) { if (input < number - 10) { message = "Too low"; Console.WriteLine(message); guesses++; } else { message = "Too low. Youre getting closer"; Console.WriteLine(message); guesses++; } } else { if (input > number + 10) { message = "Too high"; Console.WriteLine(message); guesses++; } else { message = "Too high. Youre getting closer"; Console.WriteLine(message); guesses++; } } } }
static void LeapYear() { int start = 0; int end = 9999; Console.WriteLine("-- Amazing Leap Year Calculator 2019 --"); while (true) { start = Ex01.ReadInt("First year: "); if (start < 0 || start > end) { Console.WriteLine("Year must be between 0 and 9999"); } else { break; } } while (true) { end = Ex01.ReadInt("Second year: "); if (end < start || end > 9999) { Console.WriteLine("Year must be between 0 and 9999 and less than first year."); } else { break; } } Console.WriteLine(); for (int i = start; i <= end; i++) { if (DateTime.IsLeapYear(i)) { Console.WriteLine(i + "*"); } else { Console.WriteLine(i + ""); } } }
static void FizzBuzz() { int number = Ex01.ReadInt("Enter buzzer count: "); for (int i = 1; i <= number; i++) { if (i % 3 == 0 && i % 5 == 0) { Console.WriteLine("FizzBuzz"); } else if (i % 3 == 0) { Console.WriteLine("Fizz"); } else if (i % 5 == 0) { Console.WriteLine("Buzz"); } else { Console.WriteLine(i); } } }
static void RandomVsAi() { int bot = 1; int top = 100; var random = new Random(); var number = random.Next(bot, top); int userGuess; List <int> allGuesses = new List <int>(); int AiGuess = GiveMeANumber(bot, top, allGuesses); string message; bool won = false; Console.WriteLine("Human vs super advanced AI computer. FIGHT!"); while (!won) { message = "Guess a number between 1-99: "; userGuess = Ex01.ReadInt(message); if (userGuess < 1 || userGuess > 100) { message = "Number is outside current game range. Try again"; Console.WriteLine(message); } Console.WriteLine("Human guess: " + userGuess); if (userGuess == number) { Console.WriteLine(userGuess + " is correct, human wins!"); won = true; break; } else if (userGuess < number) { if (userGuess < number - 10) { message = "Too low."; Console.WriteLine(message); allGuesses.Add(userGuess); bot = userGuess + 10; } else { message = "Too low. Youre getting closer"; Console.WriteLine(message); allGuesses.Add(userGuess); bot = userGuess + 1; top = userGuess + 11; } } else if (userGuess > number) { if (userGuess > number + 10) { message = "Too high"; Console.WriteLine(message); allGuesses.Add(userGuess); top = userGuess - 10; } else { message = "Too high. Youre getting closer"; Console.WriteLine(message); allGuesses.Add(userGuess); top = userGuess - 1; bot = userGuess - 11; } } //cpu turn //AiGuess = (bot + top) / 2; AiGuess = GiveMeANumber(bot, top, allGuesses); Console.WriteLine("AI guesses the number is: " + AiGuess); if (AiGuess == number) { Console.WriteLine(AiGuess + " is correct, AI wins!"); won = true; break; } else if (AiGuess > number) { if (AiGuess > number + 10) { message = "Too high"; Console.WriteLine(message); allGuesses.Add(AiGuess); top = AiGuess - 10; } else { message = "Too high. Youre getting closer"; Console.WriteLine(message); allGuesses.Add(AiGuess); top = AiGuess - 1; bot = AiGuess - 11; } } else if (AiGuess < number) { if (AiGuess > number + 10) { message = "Too low"; Console.WriteLine(message); allGuesses.Add(AiGuess); top = AiGuess - 10; } else { message = "Too low. Youre getting closer"; Console.WriteLine(message); allGuesses.Add(AiGuess); top = AiGuess - 1; bot = AiGuess - 11; } } } }
public Ex08() { int rows = Ex01.ReadInt("Please input size of the tree: "); renderXmas(rows); }
static void Main(string[] args) { while (true) { switch (Ex01.ReadInt("Pick Exercise 1-13, 0 to exit.")) { case 0: Environment.Exit(0); break; case 1: Ex01 exercise1 = new Ex01(); break; case 2: Ex02 exercise2 = new Ex02(); break; case 3: Ex03 exercise3 = new Ex03(); break; case 4: Ex04 exercise4 = new Ex04(); break; case 5: Ex05 exercise5 = new Ex05(); break; case 6: Ex06 exercise6 = new Ex06(); break; case 7: Ex07 exercise7 = new Ex07(); break; case 8: Ex08 exercise8 = new Ex08(); break; case 9: Ex09 exercise9 = new Ex09(); break; case 10: Ex10 exercise10 = new Ex10(); break; case 11: Ex11 exercise11 = new Ex11(); break; case 12: Ex12 exercise12 = new Ex12(); break; case 13: Ex13 exercise13 = new Ex13(); break; default: Console.WriteLine("Number not in list."); break; } Console.ReadKey(); Console.Clear(); } }