0
votes

I have the error "Error: duplicate case label", this is because i am using free pascal compiler, I have looked everywhere yet cannot find a solution, could you please provide me with one, thank you.

I will upload the full code in case there is something I am missing. Sorry that it is messy.

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.

Thank you

1

1 Answers

1
votes

It's right here:

         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; 

It should be something like:

           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; 

Also your BEGIN... END structures look fishy to me:

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;