vendredi 22 avril 2016

Checking if String Does Not Equal Something

Here is my code:

using System;

namespace FirstProgram
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            Console.WriteLine ("What is your first name?");
                String Name = Console.ReadLine ();
            Console.WriteLine ("\nHi " + Name + "! Now tell me are you a boy or girl?");
                String Sex = Console.ReadLine ();

            if (!Sex.Equals ("boy") || !Sex.Equals ("girl")) {
                Console.WriteLine ("\nERROR: You were supposed to type 'boy' or 'girl'\nPress any key to exit...");
                Console.ReadKey ();
                System.Environment.Exit (1);
            }

            Console.WriteLine ("\nOk so your name is " + Name + " and your are a " + Sex + "... Please tell me your age :)");
                int Age = Convert.ToInt32 (Console.ReadLine ());
            Console.WriteLine ("\nYou are " + Age + " years old!");
            Console.ReadKey ();
        }
    }
}

I just want to know why it exits the program even though I type "boy" or "girl" and how I can fix this.

Aucun commentaire:

Enregistrer un commentaire