lundi 12 octobre 2020

Getting strange answer when i sum 3 numbers in pascal, please help me

I get a strange answer when executing the program, can you help me?

here are my conditions:

a) if all sides can form a triangle then calculate the perimeter

b) name the triangle based on the length of the triangle sides.

Here is the program:

program P1;

var a,b,c,p :real;
var y: boolean;
var i,o,n: string;

begin

i := 'isosceles';
o := 'equilateral';
n :='scalene';

readln(a,b,c);

if (a>0) and (b>0) and (c>0) and (a+b>c) and (a+c>b) and (b+c>a) then
 y:= true
 else
 y:=false ;

if y = true then
 p := a+b+c  ;

writeln(p);

if (a=b) and (b<>c) or (b=c) and (c<>a) or (a=c) and (c<>b) then write(i);
if (a=b) and (a=c) and (b=c) then write(o);
if (a<>b) and (b<>c) and (c<>a) then write(n);

readln();
end.    

and here is what i get if i put 5,5,6

5
5
6
 1.6000000000000000E+001
isosceles

where is my mistake?

also is there a simplier way to write point b) ?

thanks

Aucun commentaire:

Enregistrer un commentaire