Nope, this will give an wrong negative value. See also Albert Ballinger's message. You should change also the tests from "i % 2 = 0" to "i % 2 = 1".
Vlad
>David thanks i've tried already several combinations using FOR and DO WHILE and no luck yet, but looking at your translation in this next line you added a -48, is there any purpose for it?
>
>"digit = val( substr( tempCustStr, i, 1 ) ) - 48"
>
>Thanks,
>
>Gil
>
>
>>
>>I think this will give you the same result as the C code:
>>rhs = 0
>>for i = strlen( tempCustStr ) to 1 step -1
>> digit = val( substr( tempCustStr, i, 1 ) ) - 48
>> if ( i % 2 = 0 )
>> rhs = rhs + digit
>> else
>> rhs = rhs + int( 2 * digit / 10 ) + ( 2 * digit ) % 10
>> endif
>>endfor
>>
>>rhs = 99 - rhs
>>checkdigit = int( rhs / 10 )
>>lastdigit = rhs % 10
>>
>>
>>>Hi everyone, I've been cracking my head trying to translate this cycle and into FP code; so far I haven't had any luck. If anybody can, please help.
>>>
>>>*Sample value:
>>>tempCustStr = '50400000019'
>>>
>>>****C++ code:******
>>>rhs = 0
>>>for (i = strlen(tempCustStr)-1;i>=0;i--){
>>> digit = *(tempCustStr + i) - '0'
>>> if (i % 2 == 0) {
>>> rhs += digit;
>>> //odd digits
>>> } else {
>>> rhs += (2 * digit) /10 + (2 * digit) % 10;
>>> }
>>>}
>>>
>>>rhs = 99 - rhs
>>>checkdigit = rhs / 10
>>>lastdigit = rhs % 10
>>>
>>>****My FP code: (It's not working properly)******
>>>rhs = 0
>>>i = LEN(tempCustStr) - 1
>>>DO WHILE i >= 0
>>> digit = VAL(SUBST(tempCustStr,i,1))
>>> IF i % 2 = 0
>>> rhs = rhs + digit
>>> ELSE
>>> rhs = rhs + ((2 * digit)/10) + ((2 * digit) % 10)
>>> ENDIF
>>> i = i - 1
>>>ENDDO
>>>
>>>rhs = 99 - rhs
>>>checkdigit = rhs /10
>>>lastdigit = rhs % 10
>>>
>>>Thanks a lot, I really appreciate any help
>>>
>>>Have a good day,
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only