PROGRAM repeating_decimal;
{Program written by Timothy Boronczyk to determin decimal value of a user}
{given fraction and declairs number of repeated decimals (if any).  2/4/97.}
 USES
  crt;
 VAR
  numerator, denominator: integer;
  again: boolean;

 PROCEDURE get_info (VAR num, denom: integer);
{procedure designed to get values from user to produce a fraction with}
 BEGIN
  write('Please enter numerator:  ');
  readln(num);
  write('Please enter denominator:  ');
  readln(denom);
 END;

 PROCEDURE solve_for_decimals (n, d:integer);
{procedure to solve for decimal and number of repeats}
 VAR
  oldn, answer, temp, count: integer;
 BEGIN
  write(n:1,'/',d:1,' = ');
  IF n MOD d= 0 THEN
   BEGIN
    answer:= n DIV d;
    write(answer:1);
    writeln;
    writeln('No repeats');
   END
  ELSE
   BEGIN
    answer:= n DIV d;
    write(answer:1, '.');
    count:= 0;
    oldn:= n;
    REPEAT
     count:= count+1;
     n:= n * 10;
     answer:= n DIV d;
     write(answer:1);
     temp:= answer * d;
     n:= n-temp;
    UNTIL (n= oldn) or (n= 0);
    writeln;
    IF n= 0 THEN
     writeln('Does not repeat.')
    ELSE
     writeln('Repeats= ', count:1);
   END;
  END;

  PROCEDURE get_again (VAR againvar: boolean);
   VAR
    a: char;
   BEGIN
    againvar:= false;
    writeln;
    write('Again (y/n):  ');
    readln(a);
    IF (a='Y') OR (a='y') THEN
     againvar:= true;
   END;

BEGIN
 CLRSCR;
 writeln('REPEATING  DECIMALS':46);
 writeln('Timothy Boronczyk':45);
 writeln;
 REPEAT
  get_info(numerator, denominator);
  writeln;
  solve_for_decimals(numerator, denominator);
  get_again(again);
  writeln;
 UNTIL again= false;
END.