Float, speed units VB.Net Exercise - Visual Basic Programming Course


 Lesson

Basic Data Types

 Exercise

Float, speed units

Objetive

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).

Code

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

More VB.Net Exercises of Basic Data Types

 Char
Write a program to ask the user for three letters and display them in reverse order....
 Triangle
Write a Visual Basic (VB.Net) program that prompts for a symbol and a width, and displays a triangle of that width, using that number for the inner sy...
 Password as string
Write a Visual Basic (VB.Net) program to ask the user for their username and password (both should be strings) and repeat it as many times as necessar...
 Password 5 attempts
Write a Visual Basic (VB.Net) program that prompts the user for their username and password. Both should be strings. After 5 incorrect attempts, the u...
 Calculator - if
Write a Visual Basic (VB.Net) program that asks the user for two numbers and an operation to perform on them (+,-,*,x,/) and displays the result of th...
 Calculator - switch
Write a Visual Basic (VB.Net) program that asks the user for two numbers and an operation to perform on them (+,-,*,x,/) and displays the result of th...
 Double
Calculate the perimeter, area, and diagonal of a rectangle, given its width and height. (Hint: use y = Math.Sqrt(x) to calculate a square root)...
 Calculate values of a function
Create a program in Visual Basic (VB.Net) to display certain values of the function y = x^2 - 2x + 1 (using integer numbers for x, ranging from -10 to...
 Display a function
Create a program to "draw" the graphic of the function y = (x-4)2 for integer values of x ranging -1 to 8. It will show as many asterisks on screen as...
 Sphere, float
Calculate the surface area and volume of a sphere, given its radius (surface area = 4 * pi * radius squared; volume = 4/3 * pi * radius cubed). Not...
 Vowel - switch
Create a Visual Basic (VB.Net) program to ask the user for a symbol and respond whether it is a vowel (in lowercase), a digit, or any other symbol, us...
 Vowel - if
Create a Visual Basic (VB.Net) program to ask the user for a symbol and respond if it's a vowel (in lowercase), a digit, or any other symbol, using "i...
 Triangle, NorthEast
Write a Visual Basic (VB.Net) program which asks for a width, and displays a triangle like this one: Enter the desired width: 5 ***** _**** __...
 Prime factors
Create a Visual Basic (VB.Net) program that displays a number (entered by the user) as a product of its prime factors. For example, 60 = 2 · 2 · 3 · 5...
 If, symbols
Create a program to ask the user for a symbol and answer if is an uppercase vowel, a lowercase vowel, a digit or any other symbol, using "if"....
 Char + for
Create a program to write the letters "B" to "N" (uppercase), using "for"...
 Double, approximation of Pi
Create a program to calculate an approximation for PI using the expression: pi/4 = 1/1 - 1/3 + 1/5 -1/7 + 1/9 - 1/11 + 1/13 ... The user will in...
 Perimeter Area
Create a program to calculate the perimeter, area and diagonal of a rectangle from its width and height (perimeter = sum of the four sides, area = bas...
 Hexadecimal and binary
Create a Visual Basic (VB.Net) program to ask the user for a number an display it both in hexadecimal and binary. It must repeat until the user enters...
 Binary
Create a Visual Basic (VB.Net) program that asks the user for a decimal number and displays its equivalent in binary form. It should be repeated until...
 Conditional and boolean
Create a Visual Basic (VB.Net) program that uses the conditional operator to give a boolean variable named "bothEven" the value "true" if two numbers ...
 Exceptions V2
Create a program to ask the user for a real number and display its square root. Errors must be trapped using "try..catch". Does it behave as you ex...


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