2015-06-02 2 views
0

Я сделал калькулятор, который должен работать, но не работает. Единственная часть, которая работает, - это дополнение. это мой код:applescript Калькулятор не работает

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 

это код приложения. Прошу прощения, если это вопрос, но мне нужна помощь. Благодаря!

ответ

0

Вы используете три оператора if/end if для обработки возвращенной кнопки, вы должны использовать только один if/end и использовать else if между ними. Я отредактировал ваш код, чтобы исправить его, и прокомментировал неправильные регионы.

.: например

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 
+0

Спасибо, что установил ее. Извините, я отклонил изменение, я не заметил изменений – samrockw22

+0

Добро пожаловать. –

Смежные вопросы