Function GetMinMax Learn programming Visual Basic (VB.net)

Lesson:

Functions


Exercise:

Function GetMinMax


Objetive:

Create a function named "GetMinMax", which will ask the user for a minimum value (a number) and a maximum value (another number). It should be called in a similar way to

GetMinMax( n1, n2);

which would behave like this:
Enter the minimum value: 5
Enter the maximum value: 3.5
Incorrect. Should be 5 or more.
Enter the maximum value: 7

That is: it should ask for the minimum value and then for the maximum. If the maximum is less than the minimum, it must be reentered. It must return both values.


Code:

Imports System
Public Class exercise132
    Public Shared Sub GetMinMax(ByRef number1 As Single, ByRef number2 As Single)
        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())
        End While
    End Sub

    Private Shared Sub Main(ByVal args As String())
        Dim number1 As Single = 000000000.00F, number2 As Single = 000000000.00F
        GetMinMax(number1, number2)
    End Sub
End Class

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.