PASCAL IF STATEMENT

2011-04-21 12:56 am
eg. IF the total cost ( cost ) of the bill is greater than $1000, a 5% discount will be given.
ans. if cost > 1000 then cost := cost * 0.9

1. if the year number ( year ) is divisible by 4 but not divisible by 100, set the leap year boolean variable ( leapyear ) to TRUE, otherwise set it to FALSE.
ans. __________ ???


20分 急急

回答 (1)

2011-04-21 7:03 am
✔ 最佳答案
(0) example 都錯?? 可能你抄錯, if cost > 1000 then cost := cost * 0.95 ;

(1) LeapYear := ((Year mod 4) =0 ) and ((Year mod 100)<>0) ;

後記:(1)習慣性,寫完乜都要打分號。
(2) mod 功能係取餘數
(3) 使用 boolean 的 and 和 or 功能,一定必須要兩邊加括號,唔懶得。因為個 and 會比 = 處理先。寫成 A = 3 or B = 6 ,會睇成 A = 3 or B,後面個 = 6 會變成無法處理,所以必須加括號, (A = 3) or (B=6) 。


收錄日期: 2021-04-26 11:28:27
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20110420000051KK00688

檢視 Wayback Machine 備份