Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
applescript计算器不工作_Applescript_Calculator - Fatal编程技术网

applescript计算器不工作

applescript计算器不工作,applescript,calculator,Applescript,Calculator,我做了一个计算器,它应该能用,但不能用。唯一有效的部分是加法。这是我的代码: my Calculator() on Calculator() display dialog "Calculator" buttons {"Add", "Multiply", "Divide"} if button returned of the result is "Add" then display dialog "What plus What?" default answer

我做了一个计算器,它应该能用,但不能用。唯一有效的部分是加法。这是我的代码:

   my Calculator()
on Calculator()
    display dialog "Calculator" buttons {"Add", "Multiply", "Divide"}
    if button returned of the result is "Add" then
        display dialog "What plus What?" default answer ""
        set a to (text returned of result)
        if a is equal to "q" then
            return
        end if
        display dialog "Next number" default answer ""
        set b to (text returned of result)
        set c to a + b
        display dialog "The answer is " & c buttons {"Start Again", "Quit"}
        if button returned of the result is "Quit" then
            return
        else
            my Calculator()
        end if
    end if
    if button returned of the result is "Multiply" then
        display dialog "What times what?" default answer ""
        set a to (text returned of result)
        if a is equal to "q" then
            return
        end if
        display dialog "Next number" default answer ""
        set b to (text returned of result)
        set c to a * b
        display dialog "The answer is " & c buttons {"Start Again", "Quit"}
        if button returned of the result is "Quit" then
            return
        else
            my Calculator()
        end if
    end if
    if button returned of the result is "Divide" then
        display dialog "What divided by what?" default answer ""
        set a to (text returned of result)
        if a is equal to "q" then
            return
        end if
        display dialog "Next number" default answer ""
        set b to (text returned of result)
        set c to a / b
        display dialog "The answer is " & c buttons {"Start Again", "Quit"}
        if button returned of the result is "Quit" then
            return
        else
            my Calculator()
        end if
    end if
end Calculator
end
   end

这是一个applescript代码。如果这是一个问题,我很抱歉,但我需要帮助。谢谢

您使用三个
if/end if
语句来处理返回的按钮,您应该只使用一个
if/end
,并在两者之间使用
else if
。我已经编辑了你的代码来修复它,并注释掉了不正确的区域

e、 g:


谢谢,这就解决了。抱歉,我拒绝了编辑,我没有注意到更改
   my Calculator()
on Calculator()
    display dialog "Calculator" buttons {"Add", "Multiply", "Divide"}
    if button returned of the result is "Add" then
        display dialog "What plus What?" default answer ""
        set a to (text returned of result)
        if a is equal to "q" then
            return
        end if
        display dialog "Next number" default answer ""
        set b to (text returned of result)
        set c to a + b
        display dialog "The answer is " & c buttons {"Start Again", "Quit"}
        if button returned of the result is "Quit" then
            return
        else
            my Calculator()
        end if
    else if button returned of the result is "Multiply" then
        display dialog "What times what?" default answer ""
        set a to (text returned of result)
        if a is equal to "q" then
            return
        end if
        display dialog "Next number" default answer ""
        set b to (text returned of result)
        set c to a * b
        display dialog "The answer is " & c buttons {"Start Again", "Quit"}
        if button returned of the result is "Quit" then
            return
        else
            my Calculator()
        end if
    else if button returned of the result is "Divide" then
        display dialog "What divided by what?" default answer ""
        set a to (text returned of result)
        if a is equal to "q" then
            return
        end if
        display dialog "Next number" default answer ""
        set b to (text returned of result)
        set c to a / b
        display dialog "The answer is " & c buttons {"Start Again", "Quit"}
        if button returned of the result is "Quit" then
            return
        else
            my Calculator()
        end if
    end if
end Calculator
end
   end