我的伪代码是否有任何问题?

时间:2013-03-18 14:57:22

标签: pseudocode

这次问题涉及收费帐户验证。基本上,我们必须设计一个伪代码程序,用户输入一个帐号,程序通过将它与我们要放入数组的列表进行比较来验证它。数字应存储在数组中,我们需要使用顺序搜索算法来定位用户输入的数字。如果数字在数组中,程序将显示一条消息,指示它有效。如果没有,则显示无效。主模块有一个要求,而函数isTicketValid。我想知道我的伪代码是否合适。谢谢!

    Constant Integer SIZE = 18
    Declare String account[SIZE] = "5658845", "4520125", "7895122", 8777541",                           "8451277", "1302850", "8080152", "4562555", "5552012", "5050552", "7825877", "1250255",      "1005231", "6545231", "3852085", "7576651", "7881200", "4581002"

    Module main()
          Display "Please enter your charge account number"
          Input account
          isValidAccount(account)
    Main()

    Function Integer isValidAccount(account)
    Declare Boolean found
    Declare Integer index
    Set found = False
    Set index = 0
    While found == False AND index <= SIZE -1
          If account[index] == account Then
                Set found = True 
          Else
                Set index = index + 1
          End if
    End While
    If found Then
          Display "Your account is valid ", index + 1
    Else
          Display "Your account is not valid."
    End If
    End Function

0 个答案:

没有答案