tomblu
tomblu

Reputation: 11

Compiling pascal code error: Incompatible types: got "Char" expected "LongInt"

Could someone help me please? Everything seems good for me.

It says:

prog.pas(57,14) Error: Incompatible types: got "Char" expected "LongInt" prog.pas(66,4) Fatal: There were 1 errors compiling module, stopping

program telesa;
uses crt;
var a,b,c,r,v: real;
    valce,koule,i,j: integer;                   {a, pocet valcu a kouli}
    objemy: array[1..50] of real;               {b, objemy vsech teles}
    povrchy_valcu: array[1..50] of real;        {c, povrchy vsech krychli a valcu}
    povrchy_krychli: array[1..50] of real;  
    status: char;
begin
    clrscr;
    valce:=0;
    koule:=0;
    i:=0;
    writeln('R - krychle, V - kvádr, O - koule, C - válec, J - jehlan, A - vypsat výsledky');
    repeat 
        begin
        i:=i+1;
        write('Zadejte jaké těleso chcete zapsat: ');
        readln(status);
        if status='R'   then begin          {krychle}
                                write('Zadejte délku strany krychle v cm: ');
                                readln(a);
                                objemy[i]:=a*a*a;
                                povrchy_krychli[i]:=6*a*a;
                             end else
        if status='V'   then begin          {kvadr}
                                write('Zadejte délku první strany kvádru v cm: ');
                                readln(a);
                                write('Zadejte délku druhé strany kvádru v cm: ');
                                readln(b);
                                write('Zadejte délku třetí strany kvádru v cm: ');
                                readln(c);
                                objemy[i]:=a*b*c;
                             end else
        if status='O'   then begin          {koule}
                                write('Zadejte poloměr koule v cm: ');
                                readln(r);
                                koule:=koule+1;
                                objemy[i]:=(4*pi*r*r*r)/3;
                             end else
        if status='C'   then begin          {valec}
                                write('Zadejte poloměr podstavy válce v cm: ');
                                readln(r);
                                write('Zadejte výšku válce v cm: ');
                                readln(v);
                                valce:=valce+1;
                                objemy[i]:=pi*r*r*v;
                                povrchy_valcu[i]:=2*pi*r*(r+v);
                             end else
        if status='J'   then begin          {jehlan}
                                write('Zadejte hranu podstavy jehlanu v cm: ');
                                readln(a);
                                write('Zadejte výšku jehlanu v cm: ');
                                readln(v);
                                objemy[i]:=(a*a*v)/3;
                             end else
        if i=1 and status='A' then write('Nezadal jste žádné těleso.');
        end;
    until status='A';
    writeln('Počet válců: ',valce);
    writeln('Počet koulí: ',koule);
    for j:=1 to 50 do writeln('Objem ',j,'. tělesa je: ',objemy[j]:2:2,' cm3');
    for j:=1 to 50 do writeln('Povrch ',j,'. válce je: ',povrchy_valcu[j]:2:2,' cm2');
    for j:=1 to 50 do writeln('Povrch ',j,'. krychle je: ',povrchy_krychli[j]:2:2,' cm2');
    readln;
end.

Upvotes: 1

Views: 2598

Answers (1)

gammatester
gammatester

Reputation: 1141

There are missing parentheses, write

if (i=1) and (status='A') then write('Nezadal jste žádné těleso.');

For more information read the section operator precedence rules in your manual or online help (e.g. Free Pascal). Without the parentheses the compiler interprets your expression as

i = (1 and status) = 'A'

and this will compute the bitwise-and of the integer 1 and the char status, which is not allowed.

Upvotes: 2

Related Questions