I'm just learning to use C # in classes, and in an exercise of searching for adults and minors (with procedures and vectors) are the minors who do not deliver any value and the truth no matter how much I review it I do not find the irregularity that causes that.
I omitted part of the program to make it easier to see.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Collections;
namespace ConsoleApp4
{
class Program
{
static void Main(string[] args)
{
int[] ID = new int[100];
string[] Nombre = new string[100];
int[] FdN = new int[100]; //FdN = Fecha de Nacimiento
int[] FdI = new int[100]; //FdI = Fecha de Ingreso
Int32[] Sueldo = new Int32[100];
int[] NHE = new int[100]; //NH = Número de Horas Extras
int[] NH = new int[100]; // NHE = Número de Hijos
int[] VHE = new int[100]; //VHE = Valor Horas Extras
int posicion = 0;
int tamaño = 0;
CargaVectores(ref tamaño, ref ID, ref Nombre, ref FdN, ref FdI, ref Sueldo, ref NHE, ref NH, ref VHE);
Menu(ref ID, ref Nombre, ref posicion, ref tamaño, ref FdN, ref Sueldo, ref FdI, ref NH, ref NHE, ref VHE);
Console.ReadKey();
}
static void LeerReg(string Linea, ref int ID, ref string Nombre, ref int FdN, ref int FdI, ref Int32 Sueldo, ref int NHE, ref int NH, ref int VHE)
{
string linea = Linea;
ID = Convert.ToInt32(linea.Substring(0, 6));
Nombre = linea.Substring(10, 20);
FdN = Convert.ToInt32(linea.Substring(40, 8));
FdI = Convert.ToInt32(linea.Substring(48, 8));
Sueldo = Convert.ToInt32(linea.Substring(56, 7));
NHE = Convert.ToInt32(linea.Substring(63, 2));
NH = Convert.ToInt32(linea.Substring(65, 1));
VHE = Convert.ToInt32(linea.Substring(66, 5));
}
static void CargaVectores(ref int TamañoVectores, ref int[] ID, ref string[] Nombre, ref int[] FdN, ref int[] FdI, ref Int32[] Sueldo, ref int[] NHE, ref int[] NH, ref int[] VHE)
{
int nlinea = 1; //nlinea = número de linea
StreamReader archivo = new StreamReader("d:\Datos\Personal.txt");
string Linea = "";
while (Linea != null)
{
Linea = archivo.ReadLine();
if (Linea != null)
{
LeerReg(Linea, ref ID[nlinea], ref Nombre[nlinea], ref FdN[nlinea], ref FdI[nlinea], ref Sueldo[nlinea], ref NHE[nlinea], ref NH[nlinea], ref VHE[nlinea]);
Console.WriteLine("(" + nlinea + ")" + ID[nlinea] + " " + Nombre[nlinea] + " " + FdN[nlinea] + " " + FdI[nlinea] + " " + Sueldo[nlinea] + " " + NHE[nlinea] + " " + NH[nlinea] + " " + VHE[nlinea]);
nlinea = nlinea + 1;
}
}
TamañoVectores = nlinea;
}
static void Menu(ref int[] ID, ref string[] Nombre, ref int posicion, ref int tamaño, ref int[] FdN, ref Int32[] Sueldo, ref int[] FdI, ref int[] NH, ref int[] NHE, ref int[] VHE)
{
bool Continuar = true;
int op = 0; //op = opción
int id = 0;
while (Continuar == true)
{
Console.WriteLine("\n[Menú] \n 1) Identificación \n 2) Calcular Edad \n 3) Años en la Empresa \n 4) Mayor Sueldo \n 5) Menor Sueldo \n 6) Mayor Número de Horas Extra \n 7) Menor Número de Horas Extra \n 8) Mayor valor de Hora(s) Extra(s) pagada(s) \n 9) Menor valor de Hora(s) Extra(s) pagada(s) \n 10) Salir");
while (op < 10)
{
op = 0;
Console.WriteLine("\n\n >Ingrese la opción que desea ver: ");
op = Convert.ToInt32(Console.ReadLine());
Console.ReadKey();
while (op != 1 && op != 2 && op != 3 && op != 4 && op != 5 && op != 6 && op != 7 && op != 8 && op != 9 && op != 10)
{
Console.WriteLine("Comando no existente, ingrese uno nuevo");
op = Convert.ToInt32(Console.ReadLine());
Console.ReadKey();
}
if (op == 5)
{
MenorSueldo(Sueldo, Nombre);
Console.ReadKey();
}
}
}
}
static void MenorSueldo(int[] Lista, string[] Nombre)
{
int ubi = 0;
int menor = Lista[0];
for (int i = 0; i < Lista.Length; i++)
{
if (Lista[i] < menor)
{
menor = Lista[i];
ubi = i;
}
}
Console.WriteLine($"El empleado con el menor sueldo es {Nombre[ubi]} con un valor de {menor}");
}
}
}
The problem is that always when executing option 4 (or any one that looks for the smallest of a file) it prints me as: "The employee with the lowest salary is [an empty space] with a value of 0"
The weirdest thing, it seems to me, is that the procedure for searching for adults does not differ in almost anything, but it works without problems.
I appreciate any possible help in advance.