0

我无法完成这项工作。显然,我不能在 case 语句中使用 > 或 <,是否有解决方法?谢谢!

case num of
    0:
        begin
            cont_0 := cont_0 + 1;
        end;
    > 0:
        begin
            cont_pos := cont_pos + 1;
            sum_pos  := sum_pos + num;
        end;
    < 0:
        begin
            sum_neg := sum_neg + num;
        end;  
    else;
end;
4

2 回答 2

6
case Sign(num) of
    -1: ... 
     0: ...
     1: ...
end;

if ... else if ... else? 你决定。

于 2009-09-07T18:33:31.270 回答
0

那么不要使用case,为什么不使用if呢?

if num = 0 then
        cont_0 := cont_0 + 1;
if num > 0 then
BEGIN
        cont_pos := cont_pos + 1;
        sum_pos  := sum_pos + num;
END
if num < 0 then
        sum_neg := sum_neg + num;
于 2009-09-07T18:25:51.567 回答