0

here is my code:

program P1;

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

begin

i := 'isoscel';
o := 'echilateral';
n :='scalen';

writeln('Introduceti 3 numerele reale');
readln(a,b,c);


case (a>0) and (b>0) and (c>0) and (a+b>c) and (a+c>b) and (b+c>a) of
 true:
   begin
     p:=a+b+c;
     writeln('perimetrul este ',p);
if (a=b) and (b<>c) or (b=c) and (c<>a) or (a=c) and (c<>b) then write('triunghiul este ',i);
if (a=b) and (a=c) and (b=c) then write('triunghiul este ',o);
if (a<>b) and (b<>c) and (c<>a) then write('triunghiul este ',n);
   end;
 false:
   writeln('nu este posibil');
end;

readln();
end.

if for example i insert 5 5 5 i will get this answer:

perimetrul este  1.5000000000000000E+001
triunghiul este echilateral

but if i put a,b,c,p as integer instead of real, i get normal result:

perimetrul este 15
triunghiul este echilateral

i need my variables to be real, can you help me to get normal a answer?

  • Does this information help? https://stackoverflow.com/questions/63752793/how-to-format-a-number-in-scientific-notation. Or, more concretely, `Writeln('perimetrul este ', FloatToStr(p))` or something similar. – Andreas Rejbrand Oct 13 '20 at 12:40
  • @AndreasRejbrand it doesnt help, i get this error project1.lpr(20,35) Error: Identifier not found "FloatToStr" and i dont find anywhere how to declare this FloatToStr. I am a begginer, sorry :( – George Rabus Oct 13 '20 at 13:07
  • Then start with naming your compiler + version. With older compilers you need ot use VAL. With newer compilers (Delphi,Freepascal) you need to USES sysutils for that – Marco van de Voort Oct 13 '20 at 14:28
  • 1
    When writing real values, writeln and write will default to scientific notation, but you can tell writeln and write, how many digits to output and how many digits after the decimal point. So for example, try writeln('perimetrul este ',p:8:1); – Stuart Oct 13 '20 at 22:36

1 Answers1

1

1.500E001 is 1.5x10^1, or 15. You want a formatted value. Try

writeln(‘Here is the answer: ’, p:5:1)

That prints the result in a field width of 5 with 1 decimal digit. Adjust format as needed.

kd4ttc
  • 1,075
  • 1
  • 10
  • 28