mardi 22 mars 2016

repeat a if else statement

How do I make it after the if statement comes true it will not execute and I can re-enter another set of numbers?... to stop it though i will have it to enter -1 to exit.

static void Main(string[] args)
    {
        {
            // first enter 2016, then 2000, then 2015 and get multiple results
            int Year;
            Console.WriteLine("Please enter a year: ");
            Year = Convert.ToInt32(Console.ReadLine());
            if ((Year % 4 == 0) && (Year % 100 != 0 || Year % 400 != 0)) // <--- entered 2016
            {
                Console.WriteLine("The Year you have entered is a Leap Year {0}.", Year);
            }
            if ((Year % 4 == 0) && (Year % 100 == 0)) // <--- year 2000
            {
                Console.WriteLine("the 2000 works", Year);
            }
            if ((Year % 5 == 0) && (Year % 100 != 0)) // <--- year 2015
            {
                Console.WriteLine("2015 works", Year);
            }
            else
            {
                // startover
            }
            Console.ReadLine();
        }
    }

Aucun commentaire:

Enregistrer un commentaire