十個if 或以上,可以如何寫公式?

2008-06-29 9:17 am
我想寫以下公式, 除了用IF 外, 請問還可以用什麼公式取替呢?

1min - 45min =0.5
46min-1hr15min=1
1hr16min-1hr45min=1.5
1hr46min-2hr15min=2
2hr16min-2hr45min=2.5
2hr46min-3hr15min=3
...
...
如此類推,去到=10

回答 (1)

2008-06-30 3:03 am
✔ 最佳答案
你用咩程式?
主要係 switch/ case (唔同程式唔同command 同用法)

以C++為例,個script會係咁
var time : int;
point : double;
// time is in units of minutes
switch ( (time-15)/30 ){
case 19: point=10 ; break;
case 18: point=9.5 ; break;
...
case 1: point=1; break;
default: point= 0.5; break;
}
係睇由15min開始,有幾多個30min;
因為你呢個個案係出數字,其實仲可以用呢條式:
point = ( (time-15)/30 +1)/2 ;

ref: http://www.courseware.ust.hk/cantonese/cpp_main/cppchoice.html#PAGE8
睇 testscore/10 果個範例

ref: http://www.puiching.edu.hk/~wtchung/trace/CPP/cpp09_c.htm
用pascal 的話,語法是這樣

2008-06-29 19:06:43 補充:
} point = ( (time-15)/30 +1)/2 ;
ar, 呢條個var type唔岩,出唔到整數同幾點五,sor
參考: 仲有唔明再問我la^^


收錄日期: 2021-04-15 19:30:40
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20080629000051KK00203

檢視 Wayback Machine 備份