The Student Room Group

AQA Computer Science AS - HELP ON PSEUDOCODE (VB)

Guys I really require assistance on pseudocode I simply cannot write this piece of pseudocode into visual basics. This is the code: http://prntscr.com/7ajkpf
May someone perhaps explain and rewrite this piece of pseudocode into visual basics? Things such as when it goes "ENDFOR" how to do this?
Original post by 1017bsquad
Guys I really require assistance on pseudocode I simply cannot write this piece of pseudocode into visual basics. This is the code: http://prntscr.com/7ajkpf
May someone perhaps explain and rewrite this piece of pseudocode into visual basics? Things such as when it goes "ENDFOR" how to do this?


Hope this helps. ENDFOR is simply translated to the VB code you would to end a for loop; next. (e.g. if it said ENDDO then we would put Loop)

Anymore questions, feel free to PM me.

Dim N As Integer
Dim Binary(8) As String
Dim BinaryPoint As Integer
Dim Count As Integer
Dim Bit As Integer
Dim Column As Single
Dim whole As Integer
Dim fraction As Single
Dim Denary As Single
N = 8
For count = 1 To N
Console.WriteLine("Enter bit")
Binary(Count) = Console.ReadLine
Next

Console.WriteLine("Enter position of binary point"
BinaryPoint = Console.ReadLine()

Column = 1
whole = 0

For Bit = BinaryPoint To 1 Step -1
whole = whole + (Binary(Bit) * Column)
Column = Column * 2
Next

Column = 0.5
Fraction = 0

For Bit = BinaryPoint To N
fraction = fraction + (Binary(Bit) * Column)
Column = Column / 2
Next
Denary = (whole + fraction)
Console.WriteLine("In Decimal:" & Denary)
Reply 2
^^ Use code tags :smile:. Other than that, nice work.
Reply 3
Original post by jhjamie
Hope this helps. ENDFOR is simply translated to the VB code you would to end a for loop; next. (e.g. if it said ENDDO then we would put Loop)

Anymore questions, feel free to PM me.

Dim N As Integer
Dim Binary(8) As String
Dim BinaryPoint As Integer
Dim Count As Integer
Dim Bit As Integer
Dim Column As Single
Dim whole As Integer
Dim fraction As Single
Dim Denary As Single
N = 8
For count = 1 To N
Console.WriteLine("Enter bit":wink:
Binary(Count) = Console.ReadLine
Next

Console.WriteLine("Enter position of binary point"
BinaryPoint = Console.ReadLine()

Column = 1
whole = 0

For Bit = BinaryPoint To 1 Step -1
whole = whole + (Binary(Bit) * Column)
Column = Column * 2
Next

Column = 0.5
Fraction = 0

For Bit = BinaryPoint To N
fraction = fraction + (Binary(Bit) * Column)
Column = Column / 2
Next
Denary = (whole + fraction)
Console.WriteLine("In Decimal:" & Denary)


omfg thank you so much man and yah i will definitely pm if i need more help :smile:!
Reply 4
Original post by Async
^^ Use code tags :smile:. Other than that, nice work.


In the pseudo code it says DO LOOP, why is it that in the translated VB code there isn't a do loop?
Original post by 1017bsquad
In the pseudo code it says DO LOOP, why is it that in the translated VB code there isn't a do loop?


There is
---------------
Do

Loop
--------------

That is a do loop in VB. However, that is not what the pseudo means. It is simply stating perform the for loop.

Quick Reply

Latest