The Student Room Group

Can someone help me make this code readable?

I need to make this code readable but i don't know what is what.

Module Module1
Sub Main()

Dim B1 As Integer
Dim zz As Integer
Dim a As String
Dim thing As String
Dim b As String
Do

Console.WriteLine("A number")
B1 = Console.ReadLine()
Console.WriteLine("Another number")
zz = Console.ReadLine()
Console.WriteLine("What you want to do?")
a = Console.ReadLine()


If a = "*" Then
thing = B1 * zz
ElseIf a = "+" Then
thing = zz + B1
ElseIf a = "/" Then
thing = B1 / zz
ElseIf a = "-" Then
thing = B1 zz

End If
Console.WriteLine(thing)
Console.WriteLine("X to exit")
b = Console.ReadLine
Loop Until (b = "x")

End Sub

End Module

I know it's long, but please help me! thank you.


Reply 1
errm well you have to indent the code. But I dont know if that is due to the text formatting rather than the fact there are no indents in the code.
First, don't worry; it's really not that long.

Tip 1: Don't call variables "B1", "zz", "a", "thing" or "b"
Tip 2: Why on earth is your output a string? It should be a double, although I'm not sure if they exist in VB so I've just done real
Tip 3: You don't need a variable for the last bit
Tip 4: It might be the forums but indent your code if it isn't! :smile:

Better names include "inputNumber1", "inputNumber2", "inputOperation".

Module Module1
Sub Main()
Dim inputN1 As Integer
Dim inputN2 As Integer
Dim inputOperator As Char
Dim output As Real

Do
Console.WriteLine("A number")
inputN1 = Console.ReadLine()
Console.WriteLine("Another number")
inputN2 = Console.ReadLine()
Console.WriteLine("What you want to do?")
inputOperator = Console.ReadLine()

If inputOperator = "*" Then
output = inputN1 * inputN2
ElseIf inputOperator = "+" Then
output = inputN1 + inputN2
ElseIf inputOperator = "/" Then
output = inputN1 / inputN2
ElseIf inputOperator = "-" Then
output = inputN1 inputN2
End If

Console.WriteLine(output)
Console.WriteLine("X to exit")
Loop Until (Console.ReadLine() = "x")
End Sub
End Module

Quick Reply