How do i check if input is always an int? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How do i check if input is always an int?

I have a method

2nd Aug 2017, 8:05 AM
James Marotta
James Marotta - avatar
4 Answers
+ 1
For C++ use header ctype.h and function isdigit(variable)
2nd Aug 2017, 8:32 AM
Kartikey Sahu
Kartikey Sahu - avatar
+ 1
you can convert to int with to_i method a = gets.to_i
2nd Aug 2017, 8:40 AM
LordGhostX
LordGhostX - avatar
0
hey thanks guys sorry phone died. I want to check if what the user gives me is text then give an error and if it's an integer then run it through an if statement
2nd Aug 2017, 9:10 AM
James Marotta
James Marotta - avatar
0
temp=gets.chomp bool = temp .is_a ? integer if bool if temp < 20 do else do
2nd Aug 2017, 9:11 AM
James Marotta
James Marotta - avatar