centra

centra

  • NA
  • 19
  • 1.3k

Readline errors when user submits null or string

Nov 2 2011 12:47 PM
I am writing a console application, that gives the user a numerical choice to pick from (1-3).  I have my logic down correctly, so that if they select 1-3 it works, but will cycle back through the loop if they choose any number outside that range and write a string error message "Invalid Entry!  Please select 1-3 only.". 
The problem I am running into is that if you just hit enter, without entering anything at all, it errors out.  Or if you submit an alpha character instead of a number, it also errors out.  How do I write it so that null entries or string/char entries will not bug it out when it is looking for only an int entry? 

Answers (19)