2017-04-25 99 views
1

您好,我已经阅读了3位数月份缩写和一天的文件输入任务,并且我必须计算每个日期的Julian日期(自1月1日) 无论我在添加两个INTEGERS时做什么,我都会收到错误201(不兼容的数据类型)。我试图制作一个新程序并使其运行,但是一旦将其实施到现有代码中,它就不再适用了。这很令人沮丧,请帮助。我厌倦了这个愚蠢的班级,使我无法在网上找到狗狗帮助的语言。 下面是代码:将常量字符串添加到变量时的运行时错误201 PASCAL

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!这意味着Range check errordocumented

201范围检查错误。如果你对范围检查 编译你的程序,那么你就可以得到这个错误在下列情况下:

1.An阵列与访问指数超出其申报范围。

2.尝试为其范围外的变量(例如枚举类型)赋值。

代码中的另一个错误是,您在循环内更改了for loop控制可变对象j。这是不允许的。您必须单独保留控制变量,并使用可根据需要更改的单独变量。

您需要重新考虑嵌套的for looprepeat .. until。也许这个混乱是在尝试修正201错误的尝试中创建的。