注意:对于输入的二进制值,我重复了两次此代码。
我认为错误的程序部分目前如下:
Y is what I am using to convert the value to denary so I can add binary values together in denary form. [integer]
binarya is the input value. [string]
chart is the current character being converted. [integer]
current is the current character converted to denary. [integer]
denarya is the denary value of binarya. [integer]
Y = 1
binarya = console.readline
Len(binarya)
For i = Len(binarya) to 1 step -1
chart = Mid(binarya, i, 1)
If chart <> "1" and chart <> "0" then
Console.readline("This is not valid BINARY input, restart the code!")
Console.readline
End if
current = chart * 1 * Y
denarya = denarya + current
Y = Y * 2
Next
答案 0 :(得分:0)
你应该写信息,而不是阅读。此外,您应该在阅读后返回。
Y = 1
binarya = console.readline
Len(binarya)
For i = Len(binarya) to 1 step -1
chart = Mid(binarya, i, 1)
If chart <> "1" and chart <> "0" then
Console.WriteLine("This is not valid BINARY input, restart the code!")
Console.ReadLine
Return
End if
current = chart * 1 * Y
denarya = denarya + current
Y = Y * 2
Next