董翔宇 发表于 2008-6-7 21:14

谁能帮我看看这段tp那里出错了

program work06;
var n,y,r:integer;
begin
write('please input the year');readln(n);
write('please input the month');readln(y);
case r of
  1,3,5,7,8,10,12: r:=31;
  4,6,9,11: r:=30;
  2:begin
     if (n mod 4=0) then begin
       if (n mod 100=0)then
         begin
           if (n mod 400=0)then
              begin
                r:=31;
              end
           else
              begin
                r:=30;
              end;
         end
       else
         begin
           r:=31;
         end;
      end
     else begin
           r:=30;
          end;
   else writeln('WRONG!');
  end;
writeln('there are',r,'days in this month');
readln;
end.

董翔宇 发表于 2008-6-8 13:46

拜托

provoke 发表于 2008-6-10 13:53

2月,平年是28天,润年是29天。而不是30或31天……

董翔宇 发表于 2008-6-18 16:45

program work06;
var n,y,r:integer;
begin
write('please input the year');readln(n);
write('please input the month');readln(y);
case r of
  1,3,5,7,8,10,12: r:=31;
  4,6,9,11: r:=30;
  2:begin
     if (n mod 4=0) then begin
       if (n mod 100=0)then
         begin
           if (n mod 400=0)then
              begin
                r:=29;
              end
           else
              begin
                r:=28;
              end;
         end
       else
         begin
           r:=29;
         end;
      end
     else begin
           r:=28;
          end;
   else writeln('WRONG!');
  end;
writeln('there are',r,'days in this month');
readln;
end.
改过了,可是还是提示“error in statement”

provoke 发表于 2008-6-18 18:33

write('please input the year');readln(n);
write('please input the month');readln(y);
case r of

需要判断的是年份,并据以为月份 r 赋值,而你判断的是什么?你的 r 似乎还没有赋值,能不错吗?

最简单的方法是直接将 r 也一并输出,调试无误后再按实际需要修改。

页: [1]

编程论坛