我有错误"错误:重复案例标签",这是因为我使用的是免费的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.
谢谢
答案 0 :(得分: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;