miércoles, 30 de noviembre de 2011

EJEMPLO DE SWITCH

EJEMPLO DE SWITCH





using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;



namespace switch1

{

  class Program

   {



      static void Main(string[] args)

{

int num1, num2, res,opc;
string aux;
do
{
  Console.Clear();
  Console.SetCursorPosition(13, 3);
  Console.WriteLine("M E N U");
  Console.SetCursorPosition(10, 5);
  Console.WriteLine("1.- SUMA DE 2 NUMEROS");
  Console.SetCursorPosition(10, 6);
  Console.WriteLine("2.- VER SI X NUMERO ES PAR O NO");
  Console.SetCursorPosition(10, 7);
  Console.WriteLine("3.- SALIR");
  Console.SetCursorPosition(6, 9);
  Console.Write("QUE OPCION DESEAS? ");
  aux = Console.ReadLine();
  opc = int.Parse(aux);
  Console.Clear();
  switch (opc)
   {
     case 1:
      {
        Console.Write("TECLEA EL VALOR DEL PRIMER NUMERO ");
        aux = Console.ReadLine();
        num1 = int.Parse(aux);
        Console.Write("TECLEA EL VALOR DEL SEGUNDO NUMERO ");
        aux = Console.ReadLine();
        num2 = int.Parse(aux);
        res = num1 + num2;
        Console.WriteLine("EL RESULTADO DE LA SUMA DE " + num2 + " + " + num1 + " = " + res);
        Console.ReadKey();
        break;
       }
      case 2:
       {
         Console.Write("TECLEA EL VALOR DEL NUMERO ");
         aux = Console.ReadLine();
         num1 = int.Parse(aux);
         res = num1 % 2;
         if (res == 0)
          {
             Console.WriteLine(num1 + " ES PAR");
           }
          else
           {
             Console.WriteLine(num1 + " ES IMPAR");
            }
        Console.ReadKey();
        break;
       }
     case 3:
      {
        break;
       }
     default:
      {
        Console.WriteLine("TE EQUIVOCASTE PON MAS ATENCION SOLO ES DEL 1 AL 3 BYE");
        Console.ReadKey();
        break;
       }
  }

     }

     while (opc != 3);
  }
 }
}

No hay comentarios:

Publicar un comentario