Statistics Learn programming Visual Basic (


Flow Control




Write a Visual Basic ( program to calculate various basic statistical operations: it will accept numbers from the user and display their sum, average, minimum and maximum, as in the following example:

Number? 5
Total=5 Count=1 Average=5 Max=5 Min=5

Number? 2
Total=7 Count=2 Average=3.5 Max=5 Min=2

Number? 0

(As seen in this example, the program will end when the user enters 0)


Imports System
Public Class exercise43
    Public Shared Sub Main()
        Dim num As Integer
        Dim total As Integer = 0, amount As Integer = 0
        Dim maximum, minimum As Integer
        Console.Write("number? ")
        num = Convert.ToInt32(Console.ReadLine())
        maximum = num
        minimum = num

        While num <> 0
            amount += 1
            total += num
            If num > maximum Then maximum = num
            If num < minimum Then minimum = num
            Console.WriteLine("Total={0} Amount={1} Average={2} maximum={3} minimum={4}", total, amount, total / amount, maximum, minimum)
            Console.Write("number? ")
            num = Convert.ToInt32(Console.ReadLine())
        End While

    End Sub
End Class

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