2017-04-25 1 views
1

안녕하세요 저는 3 자리 월 약자와 하루의 파일 입력을 읽는 작업이 주어졌으며 각각에 대한 율리우스 날짜를 계산해야합니다 (1 월 1 일 이후의 일 수) 두 개의 INTEGERS를 추가 할 때 상관없이 오류 201 (호환되지 않는 데이터 형식)이 발생합니다. 나는 새로운 프로그램을 만들려고 노력했지만 작동하도록 만들었지 만, 기존 코드에 구현하면 더 이상 작동하지 않습니다. 이것은 매우 실망 스럽습니다. 도와주세요. 나는이 어리석은 학급에 질려서 내가 온라인으로 똥을 찾을 수없는이 언어를 택하도록 돕는다.변수 파스칼에 const 문자열을 추가 할 때 런타임 오류 201

program prg6_150; 
const 
     MONABV:array[1..12] of string[03] = ('JAN','FEB','MAR','APR','MAY','JUN', 
              'JUL','AUG','SEP','OCT','NOV','DEC'); 
     MONDAYS:array[1..12] of integer = (31,28,31,30,31,30,31,31,30,31,30,31); 

var 
     more_rec:Boolean;     { EOF flag } 
     DAY:integer;       { input day } 
     MONTH:string[03];     { input month abbreviation } 
     JULIAN:integer;      { computed Julian day } 
     ch:char;        { spacer character for input } 
     FileIn:Text; 
     FileOut:Text; 

{ your module, to be called "JULIAN_DAY" inserted here } 


    procedure JULIAN_DAY; 
    var 
    j,sum_days:integer; 
    begin 
    j := 0; 
    sum_days := 0; 
    if MONTH = 'JAN' then j := 1 else 
    if MONTH = 'FEB' then j := 2 else 
    if MONTH = 'MAR' then j := 3 else 
    if MONTH = 'APR' then j := 4 else 
    if MONTH = 'MAY' then j := 5 else 
    if MONTH = 'JUN' then j := 6 else 
    if MONTH = 'JUL' then j := 7 else 
    if MONTH = 'AUG' then j := 8 else 
    if MONTH = 'SEP' then j := 9 else 
    if MONTH = 'OCT' then j := 10 else 
    if MONTH = 'NOV' then j := 11 else 
    if MONTH = 'DEC' then j := 12; 
    for J:= 2 to 12 do 
    repeat 
     sum_days := MONDAYS[1] + sum_days; 
     j := j - 1 
    until j = 1; 
    Julian := DAY + sum_days; 
    end; 

    procedure read_rec; 
    begin 
     if Eof(FileIn) then 
     more_rec := False 
     else 
     readln(FileIn,day,ch,month) 
    end; { read_rec } 

    procedure initialize; 
    begin 
     more_rec := True; 
     Assign(FileIn,'JULIAN.DAT'); 
     Reset(FileIn); 
     Assign(FileOut,'JULIAN.OUT'); 
     Rewrite(FileOut); 
     read_rec 
    end; { initialize } 

    procedure process; 
    begin 
     Julian_Day; 
     writeln(FileOut,day:2,' ',month,' ',julian:3); 
     read_rec 
    end; { process } 

    procedure wrapup; 
    begin 
     Close(FileOut); 
     Close(FileIn) 
    end; { wrapup } 

    begin { main } 
     initialize; 
     while more_rec do 
     process; 
     wrapup 
    end. 

Command Prompt Error

+0

MONDAYS [1]은 보통 MONDAYS [j-1]입니다. 일시적으로 편집하려고 시도했지만 여전히 형식 오류 hurr durr을 보냈습니다. –

답변

1

는 런타임 오류 201 incompatible types을 의미하지 않는다 : 여기 코드입니다!

1.An의 배열이에 액세스 한 : 당신이 범위에 을 확인하여 프로그램을 컴파일하는 경우

201 범위 검사 오류, 당신은 다음과 같은 경우에이 오류를 얻을 수 있습니다 : 그것은 Range check errordocumented 수단 그것의 선언 한 범위 이상으로 색인.

2. 범위 밖의 변수 (예 : 열거 형)에 값을 할당하려고 시도합니다.

코드의 또 다른 오류는 루프 내에서 for loop 컨트롤 변수 j을 변경했다는 것입니다. 그건 허용되지 않습니다. 제어 변수 만 그대로두고 필요에 따라 변경할 수있는 별도의 변수를 사용해야합니다.

중첩 된 for looprepeat .. until을 다시 생각해보아야합니다. 어쩌면 난장판은 201 오류를 수정하기위한 시행 착오 시도에서 만들어졌습니다.

관련 문제