non-integer num im KAREL

  • Hello,


    How can i use a non-integer number in a register? Im karel prg R[6] value always 0.:unamused_face:

    TP program:

    R[7]=1.2

    R[8]=1.4

    R[6]=[R7]+[R8]


    Karel:

    VAR

    reg : ARRAY[3] OF INTEGER

    status : INTEGER

    real_flag: BOOLEAN

    real_value:REAL


    BEGIN

    GET_REG(6, real_flag, reg[6], real_value, status)

    GET_REG(7, real_flag, reg[7], real_value, status)

    GET_REG(8, real_flag, reg[8], real_value, status)

    SET_INT_REG(6,reg[7]+reg[8],STATUS)


    Can somebody help me?

  • How does it "not work"? Details matter. Show your code, inputs, outputs, and error messages (if any)

    This is just a test program, it can be generated in p code, I can run the .pc file, but the register always remains 0. Also with the "SET_REAL_REG" command. If I use an integer in the value of R [7], R [8], that's fine. If R [7], R [8] is not an integer, R [6] is 0. No error message.


    code:

    PROGRAM reg_test


    %COMMENT = 'reg test'

    %ALPHABETIZE

    %NOBUSYLAMP

    %NOABORT = ERROR + COMMAND + TPENABLE

    %NOPAUSE = ERROR

    %NOPAUSESHFT



    VAR

    reg : ARRAY[10] OF INTEGER

    status : INTEGER

    real_flag: BOOLEAN

    real_value:REAL

    BEGIN

    GET_REG(6, real_flag, reg[6], real_value, status)

    GET_REG(7, real_flag, reg[7], real_value, status)

    GET_REG(8, real_flag, reg[8], real_value, status)


    SET_REAL_REG(6,reg[7]+reg[8],STATUS)


    END reg_test

  • You may be misunderstanding how GET_REG works.

    Its behavior depends on the contents of the register.

    Example 1: let R[6] = 2

    GET_REG(6, real_flag, reg[6], real_value, status)

    Result:

    real_flag = false

    reg[6] = 2

    real_value = ? (possibly uninitialized)


    Example 2: let R[6] = 2.34

    GET_REG(6, real_flag, reg[6], real_value, status)

    Result:

    real_flag = true

    reg[6] = ? (possibly uninitialized)

    real_value = 2.64

  • You're using GET_REG wrong. You're pushing the Integer result returned by GET_REG into REAL_VALUE.


    You need to create an Integer variable, as well, and:

    Code
    GET_REG (Register_Number, REAL_FLAG, INTEGER_VALUE, REAL_VALUE, STATUS)

Advertising from our partners