Ejercicio
Función GetMinMax
Objetivo
crear una función llamada "GetMinMax", que pedirá al usuario un valor mínimo (un número) y un valor máximo (otro número). Debe llamarse de manera similar a
GetMinMax( n1, n2);
que se comportarían así:
Introduzca el valor mínimo: 5
Introduzca el valor máximo: 3.5
Incorrecto. Debe ser 5 o más.
Introduzca el valor máximo: 7
Es decir: debe pedir el valor mínimo y luego el máximo. Si el máximo es inferior al mínimo, debe volver a introducirse. Debe devolver ambos valores.
Código
using System;
public class exercise132
{
public static void GetMinMax(ref float number1, ref float number2)
{
Console.Write("Enter the minimum value: ");
number1 = Convert.ToSingle(Console.ReadLine());
Console.Write("Enter the maximum value: ");
number2 = Convert.ToSingle(Console.ReadLine());
while (number2 < number1)
{
Console.WriteLine("Incorrect. Should be {0} or more.", number1);
Console.Write("Enter the maximum value: ");
number2 = Convert.ToSingle(Console.ReadLine());
}
}
static void Main(string[] args)
{
float number1 = 000000000.00f, number2 = 000000000.00f;
GetMinMax(ref number1, ref number2);
}
}