2016-03-15 52 views
0

我有错误“错误:重复的案例标签”,这是因为我使用免费的pascal编译器,我看到处处都找不到解决方案,请你给我提供一个, 谢谢。错误:重复的案例标签免费的pascal编译器

我会上传完整的代码,以防万一缺少某些东西。 对不起,这是混乱。

program diceroll; 
uses crt; 
var count,time,double,dice1,dice2:integer; 
    sum1,sum2,sum3,sum4,sum5,sum6:integer; 
    idk:boolean; 

Function Is_Double(d1,d2:integer):boolean; 
begin 
if d1 = d2 then 
    Is_Double:=true 
else 
    Is_Double:=false; 

end; 


begin 
randomize; 
clrscr; 
writeln('How many times do you want to roll the dice'); 
writeln(' '); 
readln(time); 
double:=0; 
sum1:=0; 
sum2:=0; 
sum3:=0; 
sum4:=0; 
sum5:=0; 
sum6:=0; 

repeat 
    begin 
    dice1:=random(6)+1; 
    dice2:=random(6)+1; 
    idk:=Is_Double(dice1,dice2); 
    count:= count + 1; 
    if (idk = true) then 
     begin 
      double:= double + 1; 
      writeln(dice1,' ',dice2,' ','true'); 
     end 
    else 
     writeln(dice1,' ',dice2,' ','true'); 
    end; 
    if idk=true then 
     begin 
      case dice1 of 
       1:sum1:=sum1+1; 
       1:sum2:=sum2+1; 
       1:sum3:=sum3+1;   
       1:sum4:=sum4+1;   
       1:sum5:=sum5+1; 
       1:sum6:=sum6+1; 
     end; 
until count = time; 
writeln(double); 
writeln(' '); 
writeln(' '); 
writeln(' '); 
writeln(' '); 
writeln(' Amount of doubles '); 
writeln('1 2 3 4 5 6'); 
writeln(sum1,' ',sum2,' ',sum3,' ',sum4,' ',sum5,' ',sum6); 
readln; 
end. 

谢谢

回答

1

就是这里:

  case dice1 of 
      1:sum1:=sum1+1; 
      1:sum2:=sum2+1; 
      1:sum3:=sum3+1;   
      1:sum4:=sum4+1;   
      1:sum5:=sum5+1; 
      1:sum6:=sum6+1; 

它应该是这样的:

  case dice1 of 
       1:sum1:=sum1+1; 
       2:sum2:=sum2+1; 
       3:sum3:=sum3+1;   
       4:sum4:=sum4+1;   
       5:sum5:=sum5+1; 
       6:sum6:=sum6+1; 

而且你BEGIN ... END结构看腥对我说:

repeat 
// REPEAT doesn't need BEGIN 
    dice1:=random(6)+1; 
    dice2:=random(6)+1; 
    idk:=Is_Double(dice1,dice2); 
    count:= count + 1; 
    if (idk = true) then 
     begin 
      double:= double + 1; 
      writeln(dice1,' ',dice2,' ','true'); 
     end 
    else 
     writeln(dice1,' ',dice2,' ','true'); 
// one extra END; removied - the one closing the unnecessory BEGIN at the start of REPEAT 
    if idk=true then 
     begin 
      case dice1 of 
       1:sum1:=sum1+1; 
       2:sum2:=sum2+1; 
       3:sum3:=sum3+1;   
       4:sum4:=sum4+1;   
       5:sum5:=sum5+1; 
       6:sum6:=sum6+1; 
      end;      // CASE must have an END; 
     end; 
until count = time;