*/
Check out and contribute to CodePedia, the wiki for developers.
*/

View \CONVERT.PAS

This is the second disk of the PASCAL TUTOR system. It has the

Submitted By: WEBMASTER
Rating: (Not rated) (Rate It)


(* Chapter 3 - Program 8 *)
program Convert_From_Type_To_Type;

var Index,Count : integer;
    Error_Ind   : integer;
    Size,Cost   : real;
    Letter      : char;
    Name,Amount : string[12];

begin
   Index := 65;
   Count := 66;
   Cost := 124.678;
   Amount := '12.4612';

   Letter := Chr(Index);       (* convert integer to char *)
   Size := Count;              (* convert integer to real *)

   Index := Round(Cost);       (* real to integer, rounded *)
   Count := Trunc(Cost);       (* real to integer, truncated *)

   Index := Ord(Letter);       (* convert char to integer *)
   Str(Count,Name);            (* integer to string of char *)
   Val(Amount,Size,Error_Ind); (* string to real  note that
                                  "Error_Ind" is used for
                                  returning an error code *)


   Writeln('Name is ',Name,' and Size is ',Size:10:4);
end.

corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.