Recent

Author Topic: !!!!  (Read 5840 times)

lazarusins

  • New Member
  • *
  • Posts: 17
Re: !!!!
« Reply #15 on: May 22, 2017, 04:36:45 pm »
Why when  i  start program, that i made. When i try to do division , like 2/3 it show , that it is 0 not 0.6666666667???How to correct that mistake?

lazarusins

  • New Member
  • *
  • Posts: 17
P.S tahat is tahat part of programm
« Reply #16 on: May 22, 2017, 04:47:06 pm »
Code: Pascal  [Select]
  1. Begin
  2.       clrscr;
  3.       pirm := 0; otr := 0;
  4.       write('Kalkulators');
  5.       writeln; writeln;
  6.       write('Ievadiet divus ciparus ar kuriem velaties veikt darbibas : ');
  7.       readln(pirm,otr);
  8.       write('ievadiet zimi +,-,* un / : ');
  9.       readln(zime);
  10.       if (zime = '+') then
  11.      Begin
  12.       Saskaitisana:= (pirm + otr);
  13.       Resultats := Saskaitisana;
  14.      End
  15.      else if (zime = '-') then
  16.      Begin
  17.       atnemsana := (pirm - otr);
  18.       Resultats := atnemsana;
  19.      End
  20.      else if (zime = '*') then
  21.      Begin
  22.       reizinasana := (pirm * otr);
  23.       Resultats := reizinasana;
  24.      End
  25.      else if (zime = '/') then
  26.      Begin
  27.       dalisana := (pirm DIV otr);
  28.       Resultats := dalisana;
  29.      End;
  30.       writeln;
  31.       writeln;
  32.       Write('Resultats ir ' ,Resultats,'.');
  33.       readln;
  34.      End;
  35.      end;                              

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7496
Re: !!!!
« Reply #17 on: May 22, 2017, 04:49:24 pm »
Another solution is to look at the contents of fpc/packages/symbolic/examples/easyevalexample.pp

lazarusins

  • New Member
  • *
  • Posts: 17
Re: !!!!
« Reply #18 on: May 22, 2017, 05:08:32 pm »
But how exactly make it??

Lutz Mändle

  • New Member
  • *
  • Posts: 49
Re: !!!!
« Reply #19 on: May 22, 2017, 05:16:28 pm »
You're using the operator div instead of the operator / for the division.

Handoko

  • Hero Member
  • *****
  • Posts: 3185
  • My goal: build my own game engine using Lazarus
Re: !!!!
« Reply #20 on: May 22, 2017, 05:18:31 pm »
Why when  i  start program, that i made. When i try to do division , like 2/3 it show , that it is 0 not 0.6666666667???How to correct that mistake?

Let me explain it more clearly.

Don't use div but use real division, like this:

Code: Pascal  [Select]
  1. dalisana := (pirm / otr);

Also, dalisana should be declared as real

Code: Pascal  [Select]
  1. var
  2.   dalisana: real;

Read more:
http://wiki.freepascal.org/Variables_and_Data_Types
http://wiki.freepascal.org/Div
http://wiki.freepascal.org/Assignment_and_Operations

lazarusins

  • New Member
  • *
  • Posts: 17
Re: !!!!
« Reply #21 on: May 22, 2017, 06:31:49 pm »
Thanks!
I have one more question.How to export all calculatur results to text file? :)

Handoko

  • Hero Member
  • *****
  • Posts: 3185
  • My goal: build my own game engine using Lazarus
Re: !!!!
« Reply #22 on: May 22, 2017, 06:38:37 pm »
There are many ways to do it. Read here:

http://wiki.freepascal.org/File_Handling_In_Pascal