Visual Basic coding for GCSE work

RAZER Gamer

Estimable
I have just started my Computer Science GCSE and have learnt the very basics, this work isn't for GCSE but is still being marked. I was wondering if anyone could help me add a loop to this code:

Imports System.Console

Imports System.Math

Module Module1

Private Function CtoF(Celsius As Single) As Single

Return Round(Celsius * 9 / 5 + 32, 1)

End Function

Private Function FtoC(Fahrenheit As Single) As Single

Return Round((Fahrenheit - 32) * 5 / 9, 1)

End Function

Private Function CtoK(Celsius As Single) As Single

Return Round(Celsius + 273.15, 1)

End Function

Private Function FtoK(Fahrenheit As Single) As Single

Return Round((Fahrenheit + 459.67) * 5 / 9, 1)

End Function

Private Function KtoC(Kelvin As Single) As Single

Return Round(Kelvin - 273.15, 1)

End Function

Private Function KtoF(Kelvin As Single) As Single

Return Round((Kelvin - 273.15) * 1.8 + 32, 1)

End Function

Sub Main()

Dim Fahrenheit, Celsius, Kelvin As Single

Dim UserOption As Short

BackgroundColor = ConsoleColor.DarkBlue

ForegroundColor = ConsoleColor.White

Clear()

WriteLine("WELCOME TO THE TEMERATURE CONVERSION TOOL!")

WriteLine("Please choose to convert between Celsius/Fahrenheit/Kelvin. ")

Clear()

WriteLine("List of conversion options:")

WriteLine(" (1) Please type 1 for Celsius to Fahrenheit")

WriteLine(" (2) Please type 2 for Fahrenheit to Celsius")

WriteLine(" (3) Please type 3 for Celsius to Kelvin")

WriteLine(" (4) Please type 4 for Fahrenheit to Kelvin")

WriteLine(" (5) Please type 5 for Kelvin to Celsius")

WriteLine(" (6) Please type 6 for Kelvin to Fahrenheit")

If UserOption >= 6 Then
Clear()
WriteLine("Error: Please enter a number listed 1-6")
End If

If UserOption <= 1 Then
Clear()
WriteLine("Error: Please enter a number listed 1-6")
End If

If UserOption = 1 Then

Clear()

Write("Please enter the amount in Celsius that you want to convert to Fahrenheit: ")

WriteLine("Fahrenheit = " & CtoF(Celsius))

WriteLine("Thank you for using the Temperature conversion tool!")

End If

If UserOption = 2 Then

Clear()

Write("Please enter the amount in Fahrenheit that you want to convert to Celsius: ")

WriteLine("Celsius = " & FtoC(Fahrenheit))

WriteLine("Thank you for using the Temperature conversion tool!")

End If

If UserOption = 3 Then

Clear()

Write("Please enter the amount in Celsius that you want to convert to Kelvin: ")

WriteLine("Kelvin = " & CtoK(Celsius))

WriteLine("Thank you for using the Temperature conversion tool! ")

End If

If UserOption = 4 Then

Clear()

Write("Please enter the amount in Fahrenheit that you want to convert to Kelvin: ")

WriteLine("Kelvin = " & FtoK(Fahrenheit))

WriteLine("Thank you for using the Temperature conversion tool!")

End If

If UserOption = 5 Then

Clear()

Write("Please enter the amount in Kelvin that you want to convert to Celsius: ")

WriteLine("Celsius = " & KtoC(Kelvin))

WriteLine("Thank you for using the Temperature conversion tool! ")

End If

If UserOption = 6 Then

Clear()

Write("Please enter the amount in Kelvin that you want to convert to Fahrenheit: ")

WriteLine("Fahrenheit = " & KtoF(Kelvin))

WriteLine("Thank you for using the Temperature conversion tool! ")

End If

End Sub

End Module

The code is a bit too spaced out because I copied it, but never mind, I would just like to add a restart to the:
If UserOption >= 6 Then
Clear()
WriteLine("Error: Please enter a number listed 1-6")
End If

If UserOption <= 1 Then
Clear()
WriteLine("Error: Please enter a number listed 1-6")
End If

Or an application restart, basically I want the error to restart the program.

Thanks

martinch

Estimable
Logically, you want something like:

while (true)
begin
// Print options, read selection and act accordingly
end while

I'll leave how to code it and the body of the loop as an exercise for you

Replies
2
Views
15K
Replies
3
Views
2K
Replies
0
Views
8K
Replies
1
Views
5K
Replies
1
Views
4K