I am a very beginner programmer that is taking a class in school. We have a project where we are required to check if a user input is an integer, if it is not, we have to return an error message. Would anybody know how to do such a thing?
Asked
Active
Viewed 56 times
0
-
1Possible duplicate of [Checking input value is an integer](https://stackoverflow.com/questions/18728754/checking-input-value-is-an-integer) – Pierre Ghaly May 01 '18 at 18:52
-
You tagged BASIC as in the [BASIC language](https://en.wikipedia.org/wiki/BASIC). Is this what you really want? If not, please tag the actual language in which you need your solution. – Vasan May 01 '18 at 18:58
-
I downvoted the question because the original poster has not responded to the comments asked two days ago. – Bill Hileman May 04 '18 at 13:59
2 Answers
0
Check input value is integer:
REM check if user input is integer
PRINT "Input";
INPUT X$
IF VAL(X$) THEN
PRINT "Input is numeric value"
END IF

eoredson
- 1,167
- 2
- 14
- 29
0
Check if input is integer or fractional EDIT: 05/07/2018 to include error checking
REM check if user input is integer
ON ERROR GOTO 100
PRINT "Input";
INPUT X$
IF VAL(X$) THEN
IF INSTR(X$, ".") THEN
PRINT "Input is fractional"
ELSE
PRINT "Input is numeric value"
END IF
END IF
END
100 IF ERR = 6 THEN PRINT "Overflow"
END

eoredson
- 1,167
- 2
- 14
- 29
-
Of course at this point you could check the input string for E or D which indicate exponents. – eoredson May 05 '18 at 04:55