# Getting an Int value from keyboard

**URL:** <https://forum.crystal-lang.org/t/getting-an-int-value-from-keyboard/6205>\
**Category:** Help & Support\
**Created:** [December 6, 2023, 2:06am UTC](https://forum.crystal-lang.org/t/getting-an-int-value-from-keyboard/6205 "2023-12-06T02:06:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BassGT](https://avatars.discourse-cdn.com/v4/letter/b/97f17d/32.png) [@BassGT](https://forum.crystal-lang.org/u/BassGT)\
**Post date:** [December 6, 2023, 2:06am UTC](https://forum.crystal-lang.org/t/getting-an-int-value-from-keyboard/6205/1 "2023-12-06T02:06:19Z")

</div>

Hi, I have this question. Is there any way to get an Int value from keyboard without getting a string and then turning it into Int?  
I’ve been trying to do it but I only get this error

 ![20231205_214820_edit_315022643090991](https://canada1.discourse-cdn.com/flex036/uploads/crystal_lang/original/2X/d/d0c9a67de0adb7d0b83c80bbadac5aa191093666.jpeg)

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [December 6, 2023, 2:22am UTC](https://forum.crystal-lang.org/t/getting-an-int-value-from-keyboard/6205/2 "2023-12-06T02:22:30Z")

</div>

Terminal input is inherently a string, so I don’t think there’s a way to get around that. For this particular use case, it’s probably reasonable to do like `gets.not_nil!.to_i`. This approach is really only intended for if you are 100% sure it won’t be nil, but the compiler just can’t prove it.

More ideally you need to treat `nil` as a possible value an handle it accordingly with some conditional logic. E.g. if `num1` is `nil`, then print an error and exit, or have the user try again.

See [[Help] adding two numbers](https://forum.crystal-lang.org/t/help-adding-two-numbers/3635) for a related issue.

---

<div class="post-metadata">

**Author:** ![Fryguy](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/fryguy/32/1181_2.png) [@Fryguy](https://forum.crystal-lang.org/u/Fryguy)\
**Post date:** [December 13, 2023, 7:39pm UTC](https://forum.crystal-lang.org/t/getting-an-int-value-from-keyboard/6205/3 "2023-12-13T19:39:29Z")

</div>

Following up on @Blacksmoke16 's comment if you want to see the nil yourself, run your program after it compiles and hit Ctrl-D (End of Transmission / End of File character).
