2016-03-15 67 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;