Link to home
Start Free TrialLog in
Avatar of oddishwannabe
oddishwannabe

asked on

Output integers in graphics mode

How do you output integer values on-screen while in graphics mode as output and outputXY do not work!!!
Avatar of dbrunton
dbrunton
Flag of New Zealand image

Change them to a string.

In Turbo Pascal this is the Str procedure.  


Str(I, S) where I is integer to convert and S is string to place number.

Are you using Turbo because I don't recognise the out procedure?
ASKER CERTIFIED SOLUTION
Avatar of Hypo
Hypo
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of oddishwannabe
oddishwannabe

ASKER

Adjusted points to 75
Hypno, you're a god amongst men. Thank you!!
program outtext_integer;
uses Crt, Graph;

type str = array[1..7] of char;
var Gd, Gm,p: Integer;
    o : str;

procedure outtext_int(x : integer; var out : str);
var no_of_digits,i : integer;
    isnegative : boolean;
begin
    if x < 0 then isnegative := true
             else isnegative := false;
    x := abs(x);

    if x >= 10000 then  no_of_digits := 5 + ord(isnegative)
    else if x >= 1000 then no_of_digits := 4 + ord(isnegative)
    else if x >= 100 then no_of_digits := 3 + ord(isnegative)
    else if x >= 10 then no_of_digits := 2 + ord(isnegative)
    else no_of_digits := 1 + ord(isnegative);

    if isnegative then   out[1] := '-';

    i := no_of_digits;
    while x <> 0 do
    begin
         out[i] := chr(48+(x mod 10));
         x := x div 10;
         i := i - 1;
    end;
end;
begin
       Gd := Detect;
       InitGraph(Gd, Gm, '\tp\bgi');
       if GraphResult <> grOk then   Halt(1);
       outtext('Enter number: ');
       gotoxy(1,2);
       readln(p);
       outtext_int(p,o);

       writeln(o);
       outtext(o);

       readln;
       CloseGraph;
end.


You Can Use The Str Procedure To Change The Integer Value To String That OutTextXY Work With String But If You Your Value To OutPut You Can't Use The '' To Your New String ,You Can Use This Code
Var
  St:String;
  Value,Gd,Gm:Integer;
Begin
   Gd:=Detect;{Get Graph Driver}
   St:='';{To Make Your String Empty}
   InitGraph(Gd,Gm,'');{Init Your  Graphics Mode}
   Value:=10;{for Example}
   Str(Value,St);
   OutTextXY(100,50,St);{You Can See We Dont Have The '' With St Like This 'St' To Out Put The Value Of St Not St As Text}
End.
You Can Use The Str Procedure To Change The Integer Value To String That OutTextXY Work With String But If You Your Value To OutPut You Can't Use The '' To Your New String ,You Can Use This Code
Var
  St:String;
  Value,Gd,Gm:Integer;
Begin
   Gd:=Detect;{Get Graph Driver}
   St:='';{To Make Your String Empty}
   InitGraph(Gd,Gm,'');{Init Your  Graphics Mode}
   Value:=10;{for Example}
   Str(Value,St);
   OutTextXY(100,50,St);{You Can See We Dont Have The '' With St Like This 'St' To Out Put The Value Of St Not St As Text}
End.