Advertisement
kaljavi

NumberGuess

Jan 14th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 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 ConsoleApplication23
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Random rnd = new Random();
  14.             int b = rnd.Next(1, 100);
  15.             int c;
  16.             int brojpokusaja = 1;
  17.             int[] niz = new int[10];
  18.             int j;
  19.             Console.WriteLine("Pogodite koji sam broj zamislio od 1 do 100. Imate 10 pokusaja.");
  20.             for (int i = 0; i <= 10; i++)
  21.             {
  22.  
  23.                 if (i == 10) { Console.WriteLine("\nPokusali ste 10 puta. Igra je zavrsena !"); break; }
  24.                 Console.Write("\nPogodite broj: ");
  25.                 c = Convert.ToInt32(Console.ReadLine());
  26.                 niz[i] = c;
  27.                 if (c == b)
  28.                 {
  29.                     Console.WriteLine("Bravo.Pogodili ste. Imali ste {0} pokusaja.", brojpokusaja); int[] m = new int[brojpokusaja];
  30.                     for (j = 0; j < brojpokusaja; j++)
  31.                     {
  32.                         m[j] = niz[j];
  33.                     }
  34.                     for (j = 0; j < m.Length; j++)
  35.                     {
  36.                         niz[j] = m[j];
  37.                     } break;
  38.                 }
  39.                 else if (c < b)
  40.                 {
  41.                     Console.WriteLine("Ne. Ja sam zamislio veci broj od broja " + c);
  42.                     brojpokusaja++;
  43.                 }
  44.                 else if (c > b)
  45.                 {
  46.                     Console.WriteLine("Ne. Ja sam zamislio manji broj od broja " + c);
  47.                     brojpokusaja++;
  48.                 }
  49.             }
  50.             Array.Sort(niz);
  51.             for (j = 0; j < 10; j++)
  52.             {
  53.                
  54.             }
  55.            
  56.             int d;
  57.             d = niz.Length;
  58.             int max;
  59.             max = niz[d - 1];
  60.             Console.WriteLine("Najveci broj kojim ste pokusali pogadjanje je {0}", max);
  61.             int min;
  62.             min = niz[0];
  63.             Console.WriteLine("Najmanji broj kojim ste pokusali pogadjanje je {0}", min);
  64.            
  65.            
  66.             Console.ReadLine();
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement