Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace SzukanieLiczby
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. System.Console.WriteLine(" Szukanie liczby.");
  14. int liczbamax = 1024;
  15. int odgadywanaliczba = 0;
  16. String s; //zeby odczytac ciag znaku z konsoli
  17. odgadywanaliczba = liczbamax - (liczbamax / 2);
  18. liczbamax = liczbamax / 2;
  19. for (int i=0; i<10; i++)
  20. {
  21. Console.WriteLine("\n");
  22. Console.WriteLine("1 - mniejsza, 2 - wieksza, 3 - zgadlem");
  23. Console.WriteLine("Zgaduje, że twoja liczba to: "+odgadywanaliczba);
  24.  
  25. s = Console.ReadLine(); //czyta wszystko co wpopiszemu do entera
  26. int opcja = Int32.Parse(s); //zamiana ze stringa na int
  27. if(opcja == 1)
  28. {
  29. odgadywanaliczba = odgadywanaliczba - (liczbamax / 2);
  30. liczbamax = liczbamax / 2;
  31. }
  32. else if(opcja == 2)
  33. {
  34. odgadywanaliczba = odgadywanaliczba + (liczbamax / 2);
  35. liczbamax = liczbamax / 2;
  36. }
  37. else if(opcja == 3)
  38. {
  39. Console.WriteLine("Zgadłem w "+(i+1)+" próbach!!!");
  40. break;
  41. }
  42. }
  43. Console.ReadKey();
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement