samedi 21 novembre 2015

How do i go back to my menu

 static void Main(string[] args)
    {

        Console.WriteLine("************************************************");
        Console.WriteLine("*                CAESAR CIPHER                 *");
        Console.WriteLine("*                -------------                 *");
        Console.WriteLine("*    1) Encrypt plain text                     *");
        Console.WriteLine("*    2) Decrypt plain text                     *");
        Console.WriteLine("*    3) Quit                                   *");
        Console.WriteLine("************************************************");

        Console.Write("Enter your option : ");
        string num = Console.ReadLine();
        int cnum = Convert.ToInt32(num);

        Console.WriteLine();
        string n = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        string m = "DEFGHIJKLMNOPQRSTUVWXYZABC";

        if ( cnum==1)
        {
        Console.Write("Enter a string : ");
        string text = Console.ReadLine();

        Console.WriteLine();
        Console.WriteLine("Applying Caesar cipher ...");
        Console.WriteLine();
        text = text.Replace(" ", "");
        text = text.ToUpper();
        Console.WriteLine("Input Text = " + text);
        text = text.ToUpper();
        Console.Write("Output Text = ");
        text = text.Replace(" ", "");
        foreach (char i in text)
        {
            if (i >= 'A' && i <= 'Z')
            {
                int pos = n.IndexOf(i);
                Console.Write(m[pos]);

            }
            else
            {
                Console.Write(i);

            }

        }
            Console.WriteLine();
            Console.WriteLine("Press any key to return to menu");

        }
        else  if (cnum == 2)
        {
            Console.Write("Enter a string : ");
            string text = Console.ReadLine();

            Console.WriteLine();
            Console.WriteLine("Applying Caesar cipher ...");
            Console.WriteLine();
            text = text.Replace(" ", "");
            text = text.ToUpper();
            Console.WriteLine("Input Text = " + text);
            text = text.ToUpper();
            Console.Write("Output Text = ");
            text = text.Replace(" ", "");
            foreach (char i in text)
            {
                if (i >= 'A' && i <= 'Z')
                {
                    int pos = m.IndexOf(i);
                    Console.Write(n[pos]);
                }
                else
                {
                    Console.Write(i);

                }

            }
            Console.WriteLine();
            Console.WriteLine("Press any key to return to menu");
        }

        else 
        {
            Console.WriteLine("Bye!");
        }
            Console.ReadKey();
    }
}

}

this is my code how do i go back to my menu i tried goto statement but it immediately went back to my menu i want to press any key for it to go back to my menu statement i am not sure how to do it so can somehow help me out here? can i not use the switch statement and still do it using if else statements

Aucun commentaire:

Enregistrer un commentaire