Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace zgadywarka
- {
- class Program
- {
- static void Main(string[] args)
- {
- int guesses = 0;
- int max = 100;
- int guessMin = 0;
- int guessMax = max / 2;
- Console.WriteLine($"Pomysl sobie liczbe od 1 do 100");
- while (guessMin != max)
- {
- guesses++;
- Console.WriteLine($"Czy twoja liczba znajduje sie w przedziale od {guessMin} do {guessMax}?");
- string response = Console.ReadLine();
- if (response?.ToLower().FirstOrDefault() == 't') {
- max = guessMax;
- guessMax -= (guessMax - guessMin) / 2;
- } else {
- guessMin = guessMax + 1;
- int difference = max - guessMax;
- guessMax += (int) Math.Ceiling(difference / 2f);
- }
- if (guessMin + 1 == max) {
- guesses++;
- Console.WriteLine($"Czy twoja liczba to {guessMin}?");
- response = Console.ReadLine();
- if (response?.ToLower().FirstOrDefault() != 't')
- guessMin = max;
- }
- break;
- }
- }
- Console.WriteLine($"Twoja liczba to {guessMin}!");
- Console.WriteLine($"Zostala odgadnieta w {guesses} ruchach");
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment