0

I am new to programming. I am trying to figure out why when a user chooses steel and enters 1 for the distance, the result is strange.

Module Module1

Sub Main()

    Dim distance As Integer
    Dim userInput As String
    Dim airTime, waterTime, steelTime As Double
    Dim air, water, steel As Integer


    Console.WriteLine("How far will it take to travel through air, water or steel? Choose one and find out")
    Console.WriteLine("Please make your selection now: ")
    userInput = Console.ReadLine()
    Console.WriteLine("Please enter a distance in feet:")
    distance = Console.ReadLine()


    Select Case userInput
        Case "air"

            air = 10000 / 9.09
            airTime = distance / air


            Console.WriteLine("It will take {0:G} seconds to travel {1:G} feet through the air", airTime, distance)

        Case "water"
            water = 10000 / 2.04
            waterTime = distance / water


            Console.WriteLine("It will take {0:G} seconds to travel {1:G} feet through the water", waterTime, distance)


        Case "steel"
            steel = 10000 / 0.61
            steelTime = distance / steel



            Console.WriteLine("It will take {0:G} seconds to travel {1:G} feet through the steel", steelTime, distance)


    End Select

    Console.ReadKey()

End Sub

End Module

When a user enters 1 for the distance traveled for steel, the result is 6.10016470444702E-05

1 Answers1

0

6.10016470444702E-05 is just the scientific notation for the value 0.0000610016470444702 (which is probably closer to what you're expecting).

Your problem is possibly just about how to display that value without the scientific notation.

You should be able to change your format from "G" to something like "0.#########". You can of course change that base on the precision that you need.

Batesias
  • 1,914
  • 1
  • 12
  • 22