home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / sonderh1 / readri.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1987-02-03  |  2.3 KB  |  76 lines

  1. {---------------------------------------------------------------------------}
  2. {    Prozeduren zur sicheren Eingabe von REAL- und INTEGER-Zahlen           }
  3.  
  4. PROGRAM ReadRI;
  5.  
  6. VAR x : REAL;
  7.     i : INTEGER;
  8.  
  9. {---------------------------------------------------------------------------}
  10. {          erledigt fuer RealEin und IntEin die Arbeit:                     }
  11.  
  12. PROCEDURE RealIntEin (VAR zahl: REAL; x, y, n: INTEGER);
  13.  
  14. CONST Fehlerton = ^G;                      { ASCII-Zeichen 'BELL': CONTRL-G }
  15.  
  16. VAR eingabe : STRING[20];
  17.     k,
  18.     kontroll: INTEGER;
  19.  
  20. BEGIN
  21.   REPEAT
  22.     GotoXY(x,y); ClrEol;       { Bildschirmzeile bis zu deren Ende loeschen }
  23.     GotoXY(x,y); FOR k:=1 TO n DO Write('.');    { Eingabebereich markieren }
  24.     GotoXY(x,y); ReadLn(eingabe);                { Eingabe in String        }
  25.     WHILE Pos(' ', eingabe) > 0 DO     { loesche Leerzeichen in der Eingabe }
  26.       Delete(eingabe, Pos(' ', eingabe), 1);
  27.     IF Pos(',', eingabe) > 0 THEN        { ersetze Dezimalkomma durch Punkt }
  28.       eingabe[Pos(',', eingabe)] := '.';
  29.     Val(eingabe, zahl, kontroll);         { wandle Eingabestring in Zahl um }
  30.     IF kontroll > 0 THEN Write(Fehlerton);
  31.   UNTIL kontroll = 0;
  32.   GotoXY(x,y); ClrEol;
  33.   GotoXY(x,y); WriteLn(zahl:n:4);
  34. END;
  35.  
  36. {---------------------------------------------------------------------------}
  37. {                          REAL-Zahl einlesen:                              }
  38.  
  39. PROCEDURE RealEin (VAR zahl: REAL; x, y, n: INTEGER);
  40.  
  41. BEGIN
  42.   RealIntEin(zahl, x, y, n);
  43.   GotoXY(x,y); ClrEol;
  44.   GotoXY(x,y); WriteLn(zahl:n:4);
  45. END;
  46.  
  47. {---------------------------------------------------------------------------}
  48. {                      INTEGER-Zahl einlesen:                               }
  49.  
  50. PROCEDURE IntEin (VAR zahl: INTEGER; x, y, n: INTEGER);
  51.  
  52. CONST Fehlerton = ^G;
  53.  
  54. VAR hilf    : REAL;
  55.     k,
  56.     ok      : BOOLEAN;
  57.  
  58. BEGIN
  59.   REPEAT
  60.     RealIntEin(hilf, x, y, n);
  61.     ok := (ABS(Hilf) <= MaxInt);
  62.     IF NOT ok THEN Write(Fehlerton);
  63.   UNTIL ok;
  64.   zahl := Round(hilf);                  { Realzahl wird zu Integer gerundet }
  65.   GotoXY(x,y); ClrEol;
  66.   GotoXY(x,y); WriteLn(zahl:n);
  67. END;
  68.  
  69. {---------------------------------------------------------------------------}
  70.  
  71. BEGIN { Hauptprogramm }
  72.    ClrScr;
  73.    RealEin(x, 10, 10, 10);
  74.    IntEin(i, 10, 12, 10);
  75. END.
  76.