SB Converter

Annotations

Key

// = comment/annotation

Code

//Used for conversions later, we need to initialise the values first

kgToLbs = 2.20462

kgToSt = 0.157473


//Write an intro to the screen

TextWindow.WriteLine("Welcome to the converter for metric measures.")

TextWindow.WriteLine("Valid units are kg, lbs and st.")

//Prompt the user for input

TextWindow.Write("Enter a value, then a space, then a unit: ")

//Get the input

rawInput = TextWindow.Read()

//Get the substring of the first part (The value)

value = Text.GetSubText(rawInput, 1, Text.GetIndexOf(rawInput, " "))

//Get the last bit of the string (the measurement)

measure = Text.GetSubTextToEnd(rawInput, Text.GetIndexOf(rawInput, " ") + 1)

//Check if the measure is valid (only way I could figure out how to do this)

If measure = "kg" Or measure = "lbs" Or measure = "st" Then

Else

//If it isn't valid, says so and exit

TextWindow.WriteLine("Invalid measure!")

Program.Delay(2000)

Program.End()

EndIf


//Change value to an integer

value = value + 0


//Prompt the user for the end result measurement

TextWindow.Write("What measure shall the end result be in? > ")

//Get input from the prompt

endMeasure = TextWindow.Read()


//Converts value to the endMeasure and prints the results

If measure = "kg" And endMeasure = "st" Then

//Use the initialised values from before to convert the code

answer = value * kgToSt

//Outputs the answer with the correct measurement

TextWindow.WriteLine("Answer: " + answer + " st")

//etc...

ElseIf measure = "kg" And endMeasure = "lbs" Then

answer = value * kgToLbs

TextWindow.WriteLine("Answer: " + answer + " lbs")

ElseIf measure = "st" And endMeasure = "kg" Then

answer = value / kgToSt

TextWindow.WriteLine("Answer: " + answer + " kg")

ElseIf measure = "st" And endMeasure = "lbs" Then

answer = value * 14

TextWindow.WriteLine("Answer: " + answer + " lbs")

ElseIf measure = "lbs" And endMeasure = "st" Then

answer = value / 14

TextWindow.WriteLine("Answer: " + answer + " st")

ElseIf measure = "lbs" And endMeasure = "kg" Then

answer = value / kgToLbs

TextWindow.WriteLine("Answer: " + answer + " kg")

Else

//If the end measurement isn't valid (all the valid ones are above) it says so and exits

TextWindow.WriteLine("Invalid end measure")

Program.Delay(2000)

Program.End()

EndIf