Good, my problem is that in the part of the code that appears the first if
of Case 1: says if (pos < vectorsize)
this I do so that the user can not add more data and does not exceed the limit,
The problem is that when you return to the main menu, the variable pos
returns to 0
so it will never get to the else
where it shows the error of limit execido, my question is How do I make it so that Do not go back to 0 every time you enter the menu?
static void Main(string[] args)
{
int oba = 0, obb = 0, obc = 0, pra = 0, prb = 0, prc = 0, proy = 0;
int opcion = 0;
int confirmacion = 0;
int ci = 0;
int vectorsize = 0;
int pos = 0;
if (vectorsize == 0)
{
Console.WriteLine("Ingrese la cantidad de alumnos.");
vectorsize = Convert.ToInt32(Console.ReadLine());
}
double[] alumnos = new double[vectorsize];
while (opcion != 4)
{
string opcionsino = "SI";
Console.Clear();
//Console.WriteLine(vectorsize);
Console.WriteLine("Bienvenido");
Console.WriteLine("");
Console.WriteLine("1-> Agregar alumno.");
Console.WriteLine("2-> Asignar notas.");
Console.WriteLine("3-> Informe.");
Console.WriteLine("4-> Salir.");
Console.WriteLine("");
Console.WriteLine("Elija una opcion.");
Console.WriteLine(pos);
opcion = Convert.ToInt32(Console.ReadLine());
switch (opcion)
{
case 1:
{
Console.Clear();
for (int i = 0; opcionsino == "SI" || opcionsino == null; i++)
{
if (pos < vectorsize)
{
for (int i2 = 0; i2 < alumnos.Length && alumnos[i2] != 0; i2++)
pos = i2 + 1;
Console.Clear();
Console.WriteLine("Ingrese la cedula del alumno sin puntos ni guiones Ej: 12345678");
ci = Convert.ToInt32(Console.ReadLine());
for (int i3 = 0; i3 < alumnos.Length; i3++)
{
confirmacion = 0;
//int control = 0;
if (ci == alumnos[i3])
{
Console.Clear();
Console.WriteLine("Alumno ya ingresado.");
Console.ReadLine();
confirmacion = 7;
break;
}
//control++;
}
}
else
{
Console.WriteLine("Limite exidido.");
break;
}
if (confirmacion != 7)
{
alumnos[pos] = ci;
pos = pos + 1;
}
Console.WriteLine("¿Deseas agregar otro alumno? Si/No.");
opcionsino = Console.ReadLine();
opcionsino = opcionsino.ToUpper();
}
Console.Clear();
Console.WriteLine("Precione una tecla para volver al menú principal.");
Console.ReadLine();
pos = 0;
break;
}
}
}
}
Thank you very much in advance.