|
Post by jarychk on Jun 27, 2019 20:37:50 GMT
I place this code here because it probably does not work, or does not work perfectly, since I have not tried it.
REM want v$ to be positive whole number and may include 0 input v$
if v$=str$(val(v$)) then if val(v$)>=0 then if val(v$)=int(val(v$)) then print "input is valid whole number" end if end if print "input is not what we want" end if
|
|
|
Post by B+ on Jun 28, 2019 14:08:01 GMT
If you did not try it, why post it? For someone else to check for you? OK
do input "(Just Enter quits) Enter some stuff to check if whole number > ";v$ if v$ = "" then print "Bye!" else if v$=str$(val(v$)) then if val(v$)>=0 then if val(v$)=int(val(v$)) then print "input is valid whole number" end if end if print "input is not what we want" end if end if loop until v$ =""
Blah! it is bad!
I tried this:
do scan print: print "Enter some stuff for me to check if whole number > "; n$ = getWholeNumber$() if n$ <> "" then print "Your number ";n$;" is OK." else print "Bye!" loop until n$ = ""
function getWholeNumber$() while asc(k$) <> 13 'enter scan k$ = input$(1) if instr("0123456789", k$) then output$ = output$ + k$ : print k$; else beep wend print getWholeNumber$ = output$ end function
|
|
ntech
Junior Member
Posts: 99
|
Post by ntech on Jul 15, 2019 18:42:31 GMT
Here's some really short code:
Call Main$
Sub Main$ Input "Enter any number > "; num
If isNegative(num) Then Print "Number is negative." Else Print "Number is positive." End if
If isWhole(num) Then Print "Number is a whole number." Else Print "Number isn't a whole number." End if End Sub
Function isNegative(number) 'Returns 1 if the number is negative. If instr(str$(number), "-") Then isNegative = 1 Else isNegative = 0 End If End Function
Function isWhole(number) 'Returns 1 if the number is a whole number. If instr(str$(number), ".") Then isWhole = 0 Else isWhole = 1 End if End Function
|
|