home *** CD-ROM | disk | FTP | other *** search
- program calc;
- {Copyright (C) 1991 Tansin A. Darcos & Company. Commercial Rights Reserved.}
-
- {Turbo 3
- const prefix = #27; {Code generated on FUNCTION KEY}
- {}
-
- {Turbo 4+}
- USES DOS,CRT;
- const prefix = #0; {Code generated on FUNCTION KEY}
- {}
-
- {Note: since you may, from time to time, want to change the help text
- included in the program, you should keep it as an include file
- rather than merging it into the program, but if you're certain
- it won't change, then merge it in. }
-
- {$I CALC.INC} {This file generated by MAKEHELP from CALC.HLP}
-
- var a,b,c:real;
- helpstate:integer;
- inhelp:boolean;
- op,
- ch:char;
-
- procedure getch; forward;
-
- procedure help;
- var j,
- x,y:integer;
-
- begin
- if not inhelp then
- begin
- x := wherex; y := wherey;
- gotoxy(1,10);
- FOR J := 1 TO Help_Index[helpstate] [2] DO
- WRITELN(Help_Text[Help_Index[helpstate] [1]+(J-1) ]);
- write('Press return to continue ');
- repeat
- inhelp := true;
- getch;
- until ch = #13;
- gotoxy(1,10);
- for J := 1 to Help_Index[helpstate] [2] + 1 DO begin
- clreol; writeln; end;
- gotoxy(x,y);
- end;
- inhelp := false;
- end;
-
- procedure getch;
- var h:integer;
-
- procedure pull;
- begin
- {Turbo 3
- read(kbd,ch);
- {}
- {turbo 4+}
- ch := readkey;
- {}
- end;
-
- begin
- while not keypressed do;
- repeat
- pull;
- if (ch = prefix) and keypressed then
- begin
- pull;
- if ch = ';' {F1} then
- begin
- help;
- ch := ' ';
- end
- end;
- until (ch in [#8,#13,'0'..'9','.','*','-','+','/']) ;
- end;
-
-
- procedure getnum(var r:real);
- var L:string[20];
- I:INTEGER;
-
- begin
- ch := ' ';
- l := '';
- repeat
- begin
- getch;
- if ch=#8 then
- begin
- if length(l)>0 then
- begin
- l[0] := chr(ord(l[0])-1);
- gotoxy(wherex-1,wherey)
- end
- end
- else
- if ch in ['0'..'9','.'] then
- begin
- l := l+ch;
- write(ch);
- end
- end;
- until (CH=#13) and (L<>'');
- val(L,R,I);
- writeln;
- end;
-
-
- begin
- clrscr;
- c := 0; a:=0; b:=0;
- gotoxy(1,25);
- write('Press F1 for Help');
- gotoxy(1,3);
- write('Enter first number: ');
- helpstate := 1;
- getnum(a);
- writeln('Enter operation code, * + / or -');
- helpstate := 2;
- repeat
- getch;
- until ch in ['*','+','/','-'];
- op := ch;
- writeln(op);
- writeln('Enter second number: ');
- helpstate := 4;
- getnum(b);
- writeln;
- write('Result of ',a:1:5,' ',op,' ',b:1:5,' is: ');
- case op of
- '*': c := a*b;
- '-': c := a-b;
- '+': c := a+b;
- '/': if b=0 then
- write(' a divide check, converted to ')
- else
- c := a/b;
- end;
- writeln(c:1:5);
- end.