2017-06-06 99 views
-1

有人能告訴我爲什麼這不起作用嗎?我不能爲了我的生活找出它爲什麼沒有。它編譯得很好,看起來很好,而且這種方法在其他地方都適用於我......真的需要一些幫助,任何人都知道什麼是錯的?從列表中選擇?

set areatype to (choose from list {"Triagles", "Trapeziums"} with prompt "What would you like to calculate the area of?" with title "Area Calculator") 

if areatype contains "Triangles" then 

    set height to text returned of (display dialog "What is the height of the triangle?" with title "Area Calculator" default answer "") 

    set base to text returned of (display dialog "What is the base of the triangle?" with title "Area Calculator" default answer "") 

    set area to (height * base)/2 

    display dialog "Area = " & area & " units squared" with title "Area Calculator" buttons {"Cancel", "Go again"} 

else 

    if areatype contains "Trapezium" then 

     set base1 to text returned of (display dialog "What is one base of the trapezium?" with title "Area Calculator" default answer "") 

     set base2 to text returned of (display dialog "What is the other base of the trapezium?" with title "Area Calculator" default answer "") 

     set area to ((a + b)/2) * h 
     display dialog "Area = " & area & " units squared" with title "Area Calculator" buttons {"Cancel", "Go again"} 


    end if 
end if 

-Thanks

+0

如果您表現出一些努力,這對於這些問題是非常有幫助的。嘗試註釋掉您的整個代碼,然後逐行添加它,然後看看會發生什麼。你應該很快找到你的答案。 – DonielF

回答

0

看看你的代碼中的第一行。您錯誤地拼寫了三角形,並且您需要將梯形中的「s」添加到代碼中的「其他」行中。

on goAgain() 

    set areatype to (choose from list {"Triangles", "Trapeziums"} with prompt "What would you like to calculate the area of?" with title "Area Calculator") 

    if areatype contains "Triangles" then 
     set height to text returned of (display dialog "What is the height of the triangle?" with title "Area Calculator" default answer "") 
     set base to text returned of (display dialog "What is the base of the triangle?" with title "Area Calculator" default answer "") 
     set area to (height * base)/2 

     display dialog "Area = " & area & " units squared" with title "Area Calculator" buttons {"Cancel", "Go again"} 

     if the button returned of the result is "Go again" then 
      goAgain() 
     else 
      return 
     end if 

    else 

     if areatype contains "Trapeziums" then 
      set base1 to text returned of (display dialog "What is one base of the trapezium?" with title "Area Calculator" default answer "") 
      set base2 to text returned of (display dialog "What is the other base of the trapezium?" with title "Area Calculator" default answer "") 
      set height2 to text returned of (display dialog "What is the height of the trapezium?" with title "Area Calculator" default answer "") 
      set area to ((base1 + base2)/2) * height2 

      display dialog "Area = " & area & " units squared" with title "Area Calculator" buttons {"Cancel", "Go again"} 

      if the button returned of the result is "Go again" then 
       goAgain() 
      else 
       return 
      end if 

     end if 
    end if 
end goAgain 

goAgain() 
+0

該代碼應該可以正常工作,但您只需爲{「Cancel」,「Go again」}按鈕配置操作 – wch1zpink

+0

Nevermind,我繼續並修復了{「Cancel」,「Go again」}}爲你的按鈕 – wch1zpink

+0

好的謝謝。我只是刪除了按鈕功能,儘量保持簡短。現在看起來很明顯,很抱歉浪費你的時間。應該更仔細一點。 –