使用给定数字自动计算

时间:2015-11-19 21:02:15

标签: vb.net

我想让CPU根据同样声明的给定数字计算声明的结果。

So far: 

    Dim ArrayOperators() As String = {"+", "-", "*", "/", "(", ")"}
    Dim GlavniBroj As Integer = GBRnb() 'Number between 1 and 999 that CPU needs to get from the numbers given below:

    Dim OsnovniBrojevi() As Integer = {OBRnb(), OBRnb(), OBRnb(), OBRnb()} '4 numbers from 1 to 9
    Dim SrednjiBroj As Integer = SBRnb() '1 number, 10, 15 or 20 chosen randomly
    Dim KrajnjiBroj As Integer = KBRnb() '25, 50, 75 or 100 are chosen randomly

    Private Function GBRnb()
        Randomize()
        Dim value As Integer = CInt(Int((999 * Rnd()) + 1))
        Return value
    End Function

    Private Function OBRnb()
        Dim value As Integer = CInt(Int((9 * Rnd()) + 1))
        Return value
    End Function

    Private Function SBRnb()
        Dim value As Integer = CInt(Int((3 * Rnd()) + 1))
        If value = 1 Then
            Return 10
        ElseIf value = 2 Then
            Return 15
        ElseIf value = 3 Then
            Return 20
        End If
        Return 0
    End Function

    Private Function KBRnb()
        Dim value As Integer = CInt(Int((4 * Rnd()) + 1))
        If value = 1 Then
            Return 25
        ElseIf value = 2 Then
            Return 50
        ElseIf value = 3 Then
            Return 75
        ElseIf value = 4 Then
            Return 100
        End If
        Return 0
    End Function

有没有办法让程序在其他数字的帮助下计算GlavniBroj(即GBRnb声明)(也没有重复),并且在给定运算符的帮助下?结果应显示在文本框中,以计算机如何使用该数字和运算符进行计算的整个过程的形式显示。我试图通过逐个编码操作使其工作,但这是很多写作...我不是完全寻找代码答案,但主要是编码算法。任何的想法?谢谢! :)

0 个答案:

没有答案