Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.pascal.borland    |    Borland Pascal was actually pretty neat    |    2,978 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 1,620 of 2,978    |
|    John Smith to All    |
|    Re: Getting a real number from the keybo    |
|    27 May 05 10:31:52    |
   
   From: assemblywizard@gmail.com   
      
   OK, let me explain more. I have no problem building a string, if that is   
   ALL I want--a character at a time... the object is to come with with a   
   WHOLE string of character digits--INCLUDING decimal point--which can be   
   converted into a REAL--EXTENDED or COMP type I CAN do math with... I know   
   how to program in assembly, C, C++, fortran, pascal, basic, cobol... I DON'T   
   NEED HELP IN PROGRAMMING SYNTAX--some of the examples are pseudocode I   
   give--I figure everyone here CAN program and needs no help in that--I have   
   been away from pascal for years and just need to make a small program   
   work--for example, the following WORKS and demonstartes how I want to use   
   VAL on a string--this is ONLY for demononstration:   
   {* pseudocode begins *}   
   var   
    s: string;   
    r, r2: real;   
    i: integer;   
    s := '123.456';   
    val(s, r, i);   
    r2 := r * 99;   
    writeln('r2 = ', r2:8:4);   
   {* pseudocode ends*}   
      
   This works also, and is ONLY for demonstration:   
   {* code begins *}   
   var   
    s: string;   
    r, r1: real;   
    i: integer;   
    readln(s);   
    val(s, r, i);   
    r1 := r * 99;   
    writeln('r1 = ', r1:8:4);   
   {* code ends *}   
      
   THIS DOES NOT WORK (although it DOES RUN--but VAL fails on the string   
   constructed), and IS what I want to do, AND the ONLY thing I AM concerned   
   about is making VAL work on the string--the syntax I can handle...:   
   {* CODE BEGINS *}   
   PROGRAM MREAL;   
      
   USES crt;   
      
   VAR   
    s: STRING;   
    r, rr: REAL;   
    ctr: INTEGER;   
    ch: CHAR;   
      
   PROCEDURE makereal;   
   BEGIN   
    ch := ' '; { just give it something that won't stop the loop }   
    ctr := 0;   
    while ch <> #13 do   
    BEGIN   
    ch := ReadKey;   
    write(ch);   
    s[ctr] := ch;   
    ctr := ctr + 1;   
    END;   
    VAL(s, r, ctr);   
    rr := r * 99;   
    writeln;   
    writeln('rr = ', rr:8:4);   
   END;   
      
   BEGIN   
    ClrScr;   
    makereal;   
   END.   
   {* CODE ENDS *}   
      
   If that cannot be understiood... I just don't know what to say... I am out   
   of words and amazed...   
      
   Warmest regards,   
   John   
      
   "F Verbeek"
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca