37 lines
980 B
Text
37 lines
980 B
Text
#define ZEROC asc("0")
|
|
|
|
function is_num( byval c as string ) as boolean
|
|
if asc(c) >= ZEROC andalso asc(c)<ZEROC+10 then return true
|
|
return false
|
|
end function
|
|
|
|
function is_good_isbn( isbn as string ) as boolean
|
|
dim as uinteger charno = 0, digitno = 0, sum = 0
|
|
dim as string*1 currchar
|
|
while charno <= len(isbn)
|
|
currchar = mid(isbn,charno,1)
|
|
if is_num(currchar) then
|
|
if digitno mod 2 = 1 then
|
|
sum += 2*(asc(currchar)-ZEROC)
|
|
end if
|
|
sum += asc(currchar)-ZEROC
|
|
digitno += 1
|
|
end if
|
|
charno += 1
|
|
wend
|
|
if sum mod 10 = 0 then
|
|
return true
|
|
else
|
|
return false
|
|
end if
|
|
end function
|
|
|
|
dim as string isbns(0 to 3) = { "978-0596528126", "978-0596528120", "978-1788399081", "978-1788399083" }
|
|
dim as uinteger i
|
|
for i = 0 to 3
|
|
if is_good_isbn( isbns(i) ) then
|
|
print isbns(i)+": good"
|
|
else
|
|
print isbns(i)+": bad"
|
|
end if
|
|
next i
|