samedi 9 mai 2015

Generating and calling random number [duplicate]

This question already has an answer here:

It's a simple game where player must guess what is age of an animal. I generate random number between 1 and 20 and call it in another method. I get error: not all code paths return a value.

   public class Animal 
    {
        public static Random AnimalAge1 = new Random();
        public int Age3 = AnimalAge1.Next(1,20);
        public int Age2
        {
            get
            {
                return Age3;
            }
            set {
                Age3 = value;
            }
        }  
        public void Fish()
        {
            Console.WriteLine("Zwierze moze miec maksymalnie 10 lat, zgadnij ile ma lat");
            int x = Convert.ToInt32(Console.ReadLine());
        }
        public int zwierze()
        {
            Animal myanimal = new Animal();
            Animal
            int AnimalAge = Age2;
            Console.WriteLine("Zwierze moze miec maksymalnie 20 lat zgadnij ile ma lat");
            int x = Convert.ToInt32(Console.ReadLine());
            if (x == AnimalAge)
            {
                Console.WriteLine("Aim higher");
                Console.ReadKey();
            }
            else if (x > AnimalAge)
            {
                Console.WriteLine("Aim below!");
                zwierze();
            }
            else
            {
                Console.WriteLine("Celuj wyzej!");
                zwierze();
            }
        }
             }




Aucun commentaire:

Enregistrer un commentaire