Float, speed units Learn programming Visual Basic (VB.net)


Basic Data Types


Float, speed units 60


Create a Visual Basic (VB.net) program to ask the user for a distance (in meters) and the time taken (as three numbers: hours, minutes, seconds), and display the speed, in meters per second, kilometers per hour and miles per hour (hint: 1 mile = 1609 meters).


Imports System
Public Class Exercise58
    Public Shared Sub Main()
        Dim distance As Single
        Dim hour, min, sec As Single
        Dim timeSec As Single
        Dim mps As Single
        Dim kph, mph As Single
        Console.Write("Enter distance(meters): ")
        distance = Convert.ToSingle(Console.ReadLine())
        Console.Write("Enter timeSec(hour): ")
        hour = Convert.ToSingle(Console.ReadLine())
        Console.Write("Enter timeSec(minutes): ")
        min = Convert.ToSingle(Console.ReadLine())
        Console.Write("Enter timeSec(seconds): ")
        sec = Convert.ToSingle(Console.ReadLine())
        timeSec = (hour * 3600) + (min * 60) + sec
        mps = distance / timeSec
        kph = (distance / 1000.0F) / (timeSec / 3600.0F)
        mph = kph / 1.609F
        Console.WriteLine("Your speed in meters/sec is {0}", mps)
        Console.WriteLine("Your speed in km/h is {0}", kph)
        Console.WriteLine("Your speed in miles/h is {0}", mph)
    End Sub
End Class