Recent

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

lazarusins

  • New Member
  • *
  • Posts: 17
!!!!
« on: May 21, 2017, 07:36:01 pm »
How to make easy caltulator with addition, subtraction ,multiplication ,division funkcions?

BlueIcaro

  • Hero Member
  • *****
  • Posts: 576
Remenber, the lazarus wiki is your friend: http://wiki.lazarus.freepascal.org/Main_Page
General questions (several lenguages) http://wiki.lazarus.freepascal.org/

sky_khan

  • Guest
Re: !!!!
« Reply #2 on: May 21, 2017, 07:42:01 pm »
Quote from: lazarusins
Ohhh that sounds soo difficult....

sky_khan

  • Guest
Re: !!!!
« Reply #3 on: May 21, 2017, 07:52:21 pm »
Will you try giving your posts a meaningful subject lines ?
"!!!", "Help!!!" -> Wrong!
"Writing a calculator","Simple program for school" -> Ok

Otherwise I'll continue to think that you are a spoiled child.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7498
Re: !!!!
« Reply #4 on: May 21, 2017, 08:49:48 pm »
Compile fpc/packages/symbolic/examples/rpnthing.pas

avra

  • Hero Member
  • *****
  • Posts: 1712
    • Additional info
Re: !!!!
« Reply #5 on: May 21, 2017, 08:52:55 pm »
« Last Edit: May 21, 2017, 08:55:27 pm by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Thaddy

  • Hero Member
  • *****
  • Posts: 9167
Re: !!!!
« Reply #6 on: May 21, 2017, 08:59:41 pm »
Compile fpc/packages/symbolic/examples/rpnthing.pas
Good idea, Reverse Polish Notation. I suggest to teach him Forth too. 8-) For simple calculators it is the ultimate paradigm. O:-)

Also https://www.youtube.com/watch?v=lJvdVGtkbeU
« Last Edit: May 21, 2017, 09:01:35 pm by Thaddy »
also related to equus asinus.

GetMem

  • Hero Member
  • *****
  • Posts: 3508
Re: !!!!
« Reply #7 on: May 21, 2017, 09:12:26 pm »
You can give TCalculatorDialog a try, everything it's implemented for you.

lazarusins

  • New Member
  • *
  • Posts: 17
Re: !!!!
« Reply #8 on: May 21, 2017, 09:18:47 pm »
program project1;
uses crt;
var i,n:byte;
    s,a:real;
    zime: Char;
 pirm,otr : Integer;
 Saskaitisana,atnemsana, reizinasana: Integer;
 dalisana : Integer;
 Resultats : Integer;
begin
   repeat
   clrscr;
   writeln;
   writeln('Lai atveertu md pirmaa uzdevuma a) piemeeru, ierakstiet skaitli 11.');
   writeln;
   writeln('Lai atveertu md pirmaa uzdevuma a) piemeeru, ierakstiet skaitli 2.');
   writeln;
   write('Skaitlis ir: ');
   readln(n);
   clrscr;
   until (n=11) or (n=2);
   case n of
   11:

   2:
end;

Begin
 clrscr;
 pirm := 0; otr := 0;
 write('Kalkulātors');
 writeln; writeln;
 write('Ievadiet divus ciparus ar kuriem vēlaties veikt darbības : ');
 readln(pirm,otr);
 write('Select zime +,-,* and / : ');
 readln(zime);
 if (zime = '+') then
Begin
 Saskaitisana:= (pirm + otr);
 Resultats := Saskaitisana;
End
else if (zime = '-') then
Begin
 atnemsana := (pirm - otr);
 Resultats := atnemsana;
End
else if (zime = '*') then
Begin
 reizinasana := (pirm * otr);
 Resultats := reizinasana;
End
else if (zime = '/') then
Begin
 dalisana := (pirm DIV otr);
 Resultats := dalisana;
End;
 writeln;
 writeln;
 Write('Resultats ir ' ,Resultats,'.');
 readln;
End.
end.



   else writeln('Shim, juusu ievadiitajam skaitlim nav adreseets neviens uzdevums!');
   end;
   writeln;
   writeln('Piespiediet taustinju "Enter", lai izveeleetos, ko dariit taalaak.');
   readln;
   clrscr;
   writeln;
   writeln('Lai izietu no programmas, ievadiet skaitli 0,');
   writeln;
   writeln('bet, lai saaktu no saakuma, ievadiet 1!');
   writeln;
   writeln;
   write('Opcija: ');
   readln(n);
   until n=0;
end.

         Why that programm is not working?Sorry for language, that is latvian.I hope it wont be problem to understand that programm.

Thaddy

  • Hero Member
  • *****
  • Posts: 9167
Re: !!!!
« Reply #9 on: May 21, 2017, 09:47:27 pm »
Sorry. I only understand Lithuanian, not Latvian, but I can make sense out of some of it.

You made some (3)  mistakes and the compiler tells you exactly where...
I changed three things and then it compiles... Now listen to the compiler. Click on the compiler message and fix...

If that is done you will still have to finish the program, but it will compile (look for missing ;  O:-))
« Last Edit: May 21, 2017, 09:49:38 pm by Thaddy »
also related to equus asinus.

lazarusins

  • New Member
  • *
  • Posts: 17
Re: !!!!
« Reply #10 on: May 21, 2017, 09:52:56 pm »
i can not find there mistakes :(

sky_khan

  • Guest
Re: !!!!
« Reply #11 on: May 21, 2017, 09:54:25 pm »
Your code does not even compile. It has no proper indents and there are too many syntax errors. At first, there can not be more than one "end." in any unit.

Btw, please use "#" button for inserting code next time.

Thaddy

  • Hero Member
  • *****
  • Posts: 9167
Re: !!!!
« Reply #12 on: May 21, 2017, 09:59:51 pm »
Your code does not even compile. It has no proper indents and there are too many syntax errors. At first, there can not be more than one "end." in any unit.

Btw, please use "#" button for inserting code next time.
That isn't very helpful. He knows it does not compile and Pascal doesn't even know about indentation. It is not Python >:D. And there are only 3 syntax errors to fix.

@lazarusins
Take a look at this:
Code: Pascal  [Select]
  1. Line 23 etc:
  2.    case n of
  3.    11:;  {it is ok to leave it unfinished, but you must terminate with a ;}
  4.  
  5.    2:;   {it is ok to leave it unfinished, but you must terminate with a ;}
  6.  
  7. Line 61:
  8. End; {Minor mistake}
  9. end.
  10.  
Now finish it and go to sleep. It is a good effort for a beginner! Success!

(Based on this you would get 6 out of 10 for your first program, even if it does not work yet..)
« Last Edit: May 21, 2017, 10:08:11 pm by Thaddy »
also related to equus asinus.

lazarusins

  • New Member
  • *
  • Posts: 17
Re: !!!!
« Reply #13 on: May 21, 2017, 10:07:38 pm »
Thanks,i corrected it but program still is not working:(

Thaddy

  • Hero Member
  • *****
  • Posts: 9167
Re: !!!!
« Reply #14 on: May 21, 2017, 10:12:19 pm »
Last time:
Code: Pascal  [Select]
  1. program project1; {$apptype console}
  2. uses crt;
  3. var i,n:byte;
  4.     s,a:real;
  5.     zime: Char;
  6.  pirm,otr : Integer;
  7.  Saskaitisana,atnemsana, reizinasana: Integer;
  8.  dalisana : Integer;
  9.  Resultats : Integer;
  10. begin
  11.    repeat
  12.    clrscr;
  13.    writeln;
  14.    writeln('Lai atveertu md pirmaa uzdevuma a) piemeeru, ierakstiet skaitli 11.');
  15.    writeln;
  16.    writeln('Lai atveertu md pirmaa uzdevuma a) piemeeru, ierakstiet skaitli 2.');
  17.    writeln;
  18.    write('Skaitlis ir: ');
  19.    readln(n);
  20.    clrscr;
  21.    until (n=11) or (n=2);
  22.    case n of
  23.    11:;
  24.  
  25.    2:;
  26. end;
  27.  
  28. Begin
  29.  clrscr;
  30.  pirm := 0; otr := 0;
  31.  write('Kalkulātors');
  32.  writeln; writeln;
  33.  write('Ievadiet divus ciparus ar kuriem vēlaties veikt darbības : ');
  34.  readln(pirm,otr);
  35.  write('Select zime +,-,* and / : ');
  36.  readln(zime);
  37.  if (zime = '+') then
  38. Begin
  39.  Saskaitisana:= (pirm + otr);
  40.  Resultats := Saskaitisana;
  41. End
  42. else if (zime = '-') then
  43. Begin
  44.  atnemsana := (pirm - otr);
  45.  Resultats := atnemsana;
  46. End
  47. else if (zime = '*') then
  48. Begin
  49.  reizinasana := (pirm * otr);
  50.  Resultats := reizinasana;
  51. End
  52. else if (zime = '/') then
  53. Begin
  54.  dalisana := (pirm DIV otr);
  55.  Resultats := dalisana;
  56. End;
  57.  writeln;
  58.  writeln;
  59.  Write('Resultats ir ' ,Resultats,'.');
  60.  readln;
  61. End;
  62. end.
  63.  
  64.  
  65.  
  66.    else writeln('Shim, juusu ievadiitajam skaitlim nav adreseets neviens uzdevums!');
  67.    end;
  68.    writeln;
  69.    writeln('Piespiediet taustinju "Enter", lai izveeleetos, ko dariit taalaak.');
  70.    readln;
  71.    clrscr;
  72.    writeln;
  73.    writeln('Lai izietu no programmas, ievadiet skaitli 0,');
  74.    writeln;
  75.    writeln('bet, lai saaktu no saakuma, ievadiet 1!');
  76.    writeln;
  77.    writeln;
  78.    write('Opcija: ');
  79.    readln(n);
  80.    until n=0;
  81. end.

There are still mistakes, but this code compiles and works *a little*.... I am not going to fix that.
This code is your code with the 3 syntax errors fixed...and nothing more...

Note that your teacher probably says the same as I did. And would help you in the same way. (Except if it is an exam)
« Last Edit: May 21, 2017, 10:15:42 pm by Thaddy »
also related to equus asinus.