Q&A

  • Case of 문 수정부탁드립니다.
함수(function) 안에 작성된 case 문인데

그 안에 IF 문이 들어가니까 Error 가 나네요.

수정 부탁드립니다.



Case theMonth of

2 :

begin

if theMonth = 2 then

result := '29'

else

result := '28';

end;

end;

4, 6, 9, 11 :

result := '30';

Else

result := '31';

End;





2  COMMENTS
  • Profile
    오범석 2001.03.03 06:51
    다음은 SysUtils 에 들어 있는 선언내용입니다.



    function IsLeapYear(Year: Word): Boolean;



    const

    MonthDays: array [Boolean] of TDayTable =

    ((31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31),

    (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31));





    이런식으로 짜면 되겠죠.



    //----------------------------------------------------------



    const

    theYear = 2001;

    theMonth = 3;

    begin

    ShowMessage( Format( '%d 년 %d 월의 마지막 날은 %d 일입니다 ',

    [ theYear, theMonth, MonthDays[ IsLeapYear( theYear), theMonth ] ]) );

    end;



    //-----------------------------------------------------------





    김현덕 wrote:

    > 함수(function) 안에 작성된 case 문인데

    > 그 안에 IF 문이 들어가니까 Error 가 나네요.

    > 수정 부탁드립니다.

    >

    > Case theMonth of

    > 2 :

    > begin

    > if theMonth = 2 then

    > result := '29'

    > else

    > result := '28';

    > end;

    > end;

    > 4, 6, 9, 11 :

    > result := '30';

    > Else

    > result := '31';

    > End;

    >

    >

  • Profile
    kylix 2001.03.03 02:12
    end가 하나 더 들어갔군요...



    Case theMonth of

    2 :

    begin

    if theMonth = 2 then

    result := '29'

    else

    result := '28';

    end; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 제거하세요...

    end;

    4, 6, 9, 11 :

    result := '30';

    Else

    result := '31';

    End;





    김현덕 wrote:

    > 함수(function) 안에 작성된 case 문인데

    > 그 안에 IF 문이 들어가니까 Error 가 나네요.

    > 수정 부탁드립니다.

    >

    > Case theMonth of

    > 2 :

    > begin

    > if theMonth = 2 then

    > result := '29'

    > else

    > result := '28';

    > end;

    > end;

    > 4, 6, 9, 11 :

    > result := '30';

    > Else

    > result := '31';

    > End;

    >

    >