home *** CD-ROM | disk | FTP | other *** search
- {---------------------------------------------------------------------------}
- { Prozeduren zur sicheren Eingabe von REAL- und INTEGER-Zahlen }
-
- PROGRAM ReadRI;
-
- VAR x : REAL;
- i : INTEGER;
-
- {---------------------------------------------------------------------------}
- { erledigt fuer RealEin und IntEin die Arbeit: }
-
- PROCEDURE RealIntEin (VAR zahl: REAL; x, y, n: INTEGER);
-
- CONST Fehlerton = ^G; { ASCII-Zeichen 'BELL': CONTRL-G }
-
- VAR eingabe : STRING[20];
- k,
- kontroll: INTEGER;
-
- BEGIN
- REPEAT
- GotoXY(x,y); ClrEol; { Bildschirmzeile bis zu deren Ende loeschen }
- GotoXY(x,y); FOR k:=1 TO n DO Write('.'); { Eingabebereich markieren }
- GotoXY(x,y); ReadLn(eingabe); { Eingabe in String }
- WHILE Pos(' ', eingabe) > 0 DO { loesche Leerzeichen in der Eingabe }
- Delete(eingabe, Pos(' ', eingabe), 1);
- IF Pos(',', eingabe) > 0 THEN { ersetze Dezimalkomma durch Punkt }
- eingabe[Pos(',', eingabe)] := '.';
- Val(eingabe, zahl, kontroll); { wandle Eingabestring in Zahl um }
- IF kontroll > 0 THEN Write(Fehlerton);
- UNTIL kontroll = 0;
- GotoXY(x,y); ClrEol;
- GotoXY(x,y); WriteLn(zahl:n:4);
- END;
-
- {---------------------------------------------------------------------------}
- { REAL-Zahl einlesen: }
-
- PROCEDURE RealEin (VAR zahl: REAL; x, y, n: INTEGER);
-
- BEGIN
- RealIntEin(zahl, x, y, n);
- GotoXY(x,y); ClrEol;
- GotoXY(x,y); WriteLn(zahl:n:4);
- END;
-
- {---------------------------------------------------------------------------}
- { INTEGER-Zahl einlesen: }
-
- PROCEDURE IntEin (VAR zahl: INTEGER; x, y, n: INTEGER);
-
- CONST Fehlerton = ^G;
-
- VAR hilf : REAL;
- k,
- ok : BOOLEAN;
-
- BEGIN
- REPEAT
- RealIntEin(hilf, x, y, n);
- ok := (ABS(Hilf) <= MaxInt);
- IF NOT ok THEN Write(Fehlerton);
- UNTIL ok;
- zahl := Round(hilf); { Realzahl wird zu Integer gerundet }
- GotoXY(x,y); ClrEol;
- GotoXY(x,y); WriteLn(zahl:n);
- END;
-
- {---------------------------------------------------------------------------}
-
- BEGIN { Hauptprogramm }
- ClrScr;
- RealEin(x, 10, 10, 10);
- IntEin(i, 10, 12, 10);
- END.