Jump to content

Programming Fundamentals/Arrays/Pseudocode

From Wikiversity

arrays.txt

[edit | edit source]
Declare Real C[101]
Declare Real F[213]

Call BuildC(C)
Call BuildF(F)
Call DisplayArray("C", C)
Call DisplayArray("F", F)
Call FindTemperature(C, F)

BuildC

[edit | edit source]
Declare Integer Index

For Index = 0 To size(C) - 1
    Set C[Index] = Index * 9 / 5 + 32
End For

BuildF

[edit | edit source]
Declare Integer Index

For Index = 0 To size(F) - 1
    Set F[Index] = (Index - 32) * 5 / 9
End For

DisplayArray

[edit | edit source]
Declare Integer Index

For Index = 0 To size(Array) - 1
    Display Name, "[", Index, "] = ", Array[Index]
End For

FindTemperature

[edit | edit source]
Declare Integer Temp
Declare Integer Size

Set Size = GetMinimumSize(C, F)
Do
    Display "Enter a temperature between 0 and ", Size - 1
    Input Temp
While Temp < 0 OR Temp > Size - 1
Display Temp, "° Celsius is ", C[Temp], "° Fahrenheit"
Display Temp, "° Fahrenheit is ", F[Temp], "° Celsius"

GetMinimumSize

[edit | edit source]
Declare Integer Size

Set Size = size(C)
If Size > size(F) Then
    Set Size = size(F)
End If

Return Size

See Also

[edit | edit source]