1
I have several variables and one of them is menor
, when checking her out (output) I realized that the same always remains at zero, because this is occurring?
int z, menor = 0, maior = 0;
for (int i = 1; i <= 5; i++)
{
Console.WriteLine("informe o valor: ");
z = int.Parse(Console.ReadLine());
if (z <= menor)
{
menor = z;
}
else if (z >= maior)
{
maior = z;
}
}
Console.WriteLine("MAIOR: " + maior);
Console.WriteLine("MENOR: " + menor);
Console.ReadLine();
This depends on the range of values that can be informed at the entrance. Ideally, you should initialize the smallest variable with the highest possible value for that data type and for the largest variable the lowest possible value to be informed for the data type. Another possibility, which is independent of these maximum and minimum values for the data type, is that you assign the lower and higher variables the value read in the first reading and in the following readings to make the appropriate checks.
– anonimo
What exactly are you trying to do there?
– user148754