static void Main(string[] args)
        {
            Crappy_Sound c_Snd = new Crappy_Sound(); //a stupid class
                Console.WriteLine(" RIP Davey Jones =< "); //a shame

               c_Snd.playSoundThatisVeryCoolAndSoundsLikeSomethingFromTheDosDays(); //very long function name.. lol

                Console.Clear(); //clear the console.

                Console.ForegroundColor = ConsoleColor.Red; //Red text
                Console.BackgroundColor = ConsoleColor.DarkBlue; //Dark blue background

                Console.Clear(); //clear the console...redundant

                Console.WriteLine("Enter an index to find your prime numbers! \n"); //print the line
                BitArray mainBitArray; //initialize bitArray
                int input_Buffer = 0; //declares a integer data type and sets it to 0! A C#, you are too sneaky =P

                while (true) //infinite loop
                {
                    try //exception handling
                    {
                        input_Buffer = int.Parse(Console.ReadLine()); //parse the input from a string to a integer

                        if (input_Buffer == 0 || input_Buffer == 1) { Console.WriteLine("Please enter a number other than 1 or 0!!\n"); c_Snd.playErrorSound(); }
                            //check to see if a 1 or 0 has been entered
                        else { break; }; //breaks out of loop

                    }
                    catch
                    {
                        Console.WriteLine("Sorry dude, not a valid number!- \nTRY AGAIN! \n"); //print this line for error
                        c_Snd.playErrorSound(); //error sound
                    }
                }

                mainBitArray = new BitArray(input_Buffer + 1); //allocate memory for bitArray !Make sure to always add one to the array index so you can display all the numbers!

                Console.Clear(); //clear the console...very redundant...

                Console.WriteLine(bSieve(mainBitArray) + "\n\n"); //prints out the data, very compact

                input_Buffer = 0; //sets the input to 0

                Console.WriteLine("Enter a number to see if it is a prime?!?!"); //dude? where is my prime number?

                while (true) //to infinity and beyond in this loop!
                {
                    try //exception handling
                    {
                        input_Buffer = int.Parse(Console.ReadLine());
                        if (input_Buffer == 0 || input_Buffer == 1) { Console.WriteLine("Please enter a number other than 1 or 0!!\n"); c_Snd.playErrorSound(); }
                            //if its a 1 or 0 show this and play the stupid ass sound
                        else { break; }; //break out of the god forsaken loop!
                    }

                    catch
                    {
                        Console.WriteLine("Sorry dude, not a valid number!- \nTRY AGAIN! \n"); //print this line for errors inside catch block
                        c_Snd.playErrorSound(); //the error sound
                    }
                }

                while (true) //infinite loop
                {
                    try //exception handling
                    {

                        if (input_Buffer >= mainBitArray.Length) //makes sure the number you entered is not outside of the instantiated index of the array
                        {

                            Console.WriteLine("You've entered a number outside the bounds of the array index,\n" + //lol
                            "Please tell me you aren't on the crack?\n" + "Please enter the number again!\n");
                            input_Buffer = int.Parse(Console.ReadLine()); //readline again
                        }
                        else
                        {

                            if (mainBitArray[input_Buffer] == true) //determines if you are correct in your choosing
                            {
                                Console.WriteLine("\n Yes, the number " + input_Buffer //You are correct!
                                    + " Is a prime number");
                                c_Snd.playGoodSound(); //I'll play the good sound for you!
                                break; //breakout!!
                            }
                            else
                            {
                                Console.WriteLine("\n No, the number " + input_Buffer //You are wrong!
                                    + " Is NOT! prime number");
                                c_Snd.playErrorSound(); //Bad sound, may your soul rot in eternal hell fire!
                                break; //breakout!!
                            };
                        }
                    }
                    catch
                    {
                        Console.WriteLine("Sorry dude, not a valid number!- \nTRY AGAIN! \n"); //print this line for errors inside catch block
                        c_Snd.playErrorSound(); //the error sound

                    }
                }

                Console.ReadLine(); //pause...
        }
示例#2
0
        static void Main(string[] args)
        {
            Crappy_Sound c_Snd = new Crappy_Sound();                             //a stupid class

            Console.WriteLine(" RIP Davey Jones =< ");                           //a shame

            c_Snd.playSoundThatisVeryCoolAndSoundsLikeSomethingFromTheDosDays(); //very long function name.. lol

            Console.Clear();                                                     //clear the console.

            Console.ForegroundColor = ConsoleColor.Red;                          //Red text
            Console.BackgroundColor = ConsoleColor.DarkBlue;                     //Dark blue background

            Console.Clear();                                                     //clear the console...redundant

            Console.WriteLine("Enter an index to find your prime numbers! \n");  //print the line
            BitArray mainBitArray;                                               //initialize bitArray
            int      input_Buffer = 0;                                           //declares a integer data type and sets it to 0! A C#, you are too sneaky =P

            while (true)                                                         //infinite loop
            {
                try                                                              //exception handling
                {
                    input_Buffer = int.Parse(Console.ReadLine());                //parse the input from a string to a integer

                    if (input_Buffer == 0 || input_Buffer == 1)
                    {
                        Console.WriteLine("Please enter a number other than 1 or 0!!\n"); c_Snd.playErrorSound();
                    }
                    //check to see if a 1 or 0 has been entered
                    else
                    {
                        break;
                    };                   //breaks out of loop
                }
                catch
                {
                    Console.WriteLine("Sorry dude, not a valid number!- \nTRY AGAIN! \n"); //print this line for error
                    c_Snd.playErrorSound();                                                //error sound
                }
            }



            mainBitArray = new BitArray(input_Buffer + 1);                   //allocate memory for bitArray !Make sure to always add one to the array index so you can display all the numbers!

            Console.Clear();                                                 //clear the console...very redundant...

            Console.WriteLine(bSieve(mainBitArray) + "\n\n");                //prints out the data, very compact

            input_Buffer = 0;                                                //sets the input to 0

            Console.WriteLine("Enter a number to see if it is a prime?!?!"); //dude? where is my prime number?


            while (true) //to infinity and beyond in this loop!
            {
                try      //exception handling
                {
                    input_Buffer = int.Parse(Console.ReadLine());
                    if (input_Buffer == 0 || input_Buffer == 1)
                    {
                        Console.WriteLine("Please enter a number other than 1 or 0!!\n"); c_Snd.playErrorSound();
                    }
                    //if its a 1 or 0 show this and play the stupid ass sound
                    else
                    {
                        break;
                    };                   //break out of the god forsaken loop!
                }

                catch
                {
                    Console.WriteLine("Sorry dude, not a valid number!- \nTRY AGAIN! \n"); //print this line for errors inside catch block
                    c_Snd.playErrorSound();                                                //the error sound
                }
            }


            while (true)                                                                                       //infinite loop
            {
                try                                                                                            //exception handling
                {
                    if (input_Buffer >= mainBitArray.Length)                                                   //makes sure the number you entered is not outside of the instantiated index of the array
                    {
                        Console.WriteLine("You've entered a number outside the bounds of the array index,\n" + //lol
                                          "Please tell me you aren't on the crack?\n" + "Please enter the number again!\n");
                        input_Buffer = int.Parse(Console.ReadLine());                                          //readline again
                    }
                    else
                    {
                        if (mainBitArray[input_Buffer] == true)                    //determines if you are correct in your choosing
                        {
                            Console.WriteLine("\n Yes, the number " + input_Buffer //You are correct!
                                              + " Is a prime number");
                            c_Snd.playGoodSound();                                 //I'll play the good sound for you!
                            break;                                                 //breakout!!
                        }
                        else
                        {
                            Console.WriteLine("\n No, the number " + input_Buffer //You are wrong!
                                              + " Is NOT! prime number");
                            c_Snd.playErrorSound();                               //Bad sound, may your soul rot in eternal hell fire!
                            break;                                                //breakout!!
                        };
                    }
                }
                catch
                {
                    Console.WriteLine("Sorry dude, not a valid number!- \nTRY AGAIN! \n"); //print this line for errors inside catch block
                    c_Snd.playErrorSound();                                                //the error sound
                }
            }



            Console.ReadLine();     //pause...
        }