
cerrar in while
Publicado por jorfe (7 intervenciones) el 30/11/2016 20:35:30
Hola el motivo de este post es para solicitar ayuda ya que tengo que crear un menu pero al aplastar la opcion 5 el rrograma se tiene que salir como veran puede un readline pero aun asi no se sale inmediantamente tengo que darle enter dos veces
int n;
int opcion;
Console.WriteLine("¿Cuantos nombres necesitas ");
n = Convert.ToInt16(Console.ReadLine());
string[] datos1 = new string[n];
int[] datos2 = new int[n];
string s = "5";
while (s == "5")
{
Console.WriteLine("¿Que opcion quieres?");
switch (opcion)
{
case 1: for (int i = 0; i < n; i++)
{
Console.Write("Escribe el nombre:");
datos1[i] = Console.ReadLine();
}
break;
case 2: for (int i = 0; i < n; i++)
{
Console.WriteLine("¿Cuantos años tiene" + " " + datos1[i] + "?:");
datos2[i] = Convert.ToInt16(Console.ReadLine());
}
break;
case 3: for (int i = 0; i < n; i++)
{
Console.WriteLine("Esta es la informacion que se ha guardado: ");
Console.WriteLine(datos1[i] + " " + "segun tu" + " " + datos2[i] + " " + "años" );
}
break;
case 4: for (int i = 0; i < n; i++)
{
if (datos2[i] >= 18)
{
Console.WriteLine("Mayores de edad:");
Console.WriteLine(datos1[i] + " " + "tiene" + " " + datos2[i] + " " + "años");
}
}
break;
case 5:
s = Console.ReadLine();
break;
}
}
Console.ReadKey();
int n;
int opcion;
Console.WriteLine("¿Cuantos nombres necesitas ");
n = Convert.ToInt16(Console.ReadLine());
string[] datos1 = new string[n];
int[] datos2 = new int[n];
string s = "5";
while (s == "5")
{
Console.WriteLine("¿Que opcion quieres?");
switch (opcion)
{
case 1: for (int i = 0; i < n; i++)
{
Console.Write("Escribe el nombre:");
datos1[i] = Console.ReadLine();
}
break;
case 2: for (int i = 0; i < n; i++)
{
Console.WriteLine("¿Cuantos años tiene" + " " + datos1[i] + "?:");
datos2[i] = Convert.ToInt16(Console.ReadLine());
}
break;
case 3: for (int i = 0; i < n; i++)
{
Console.WriteLine("Esta es la informacion que se ha guardado: ");
Console.WriteLine(datos1[i] + " " + "segun tu" + " " + datos2[i] + " " + "años" );
}
break;
case 4: for (int i = 0; i < n; i++)
{
if (datos2[i] >= 18)
{
Console.WriteLine("Mayores de edad:");
Console.WriteLine(datos1[i] + " " + "tiene" + " " + datos2[i] + " " + "años");
}
}
break;
case 5:
s = Console.ReadLine();
break;
}
}
Console.ReadKey();
Valora esta pregunta


0