I am just trying to check if the input that the user enters is an integer or something else. I know that I probably need to take the input as a string and then check every part of the string. But I am still lost with how to implement it.
Asked
Active
Viewed 53 times
0
-
4With any programming problem (but especially with assembler), you need to break it down into manageable steps. For example, let's say you had the user enter just 1 character. How would you check to see if it was a number? Well, what does it mean to be a number? Is 'Q' a number? How about '7'? With that in mind, how would you check to see if what they entered was a number? While you could check each of the possible values for a number (0-9), it turns out that all digits are right next to each other in the list of characters. So you can check to see if each character < '0' or > '9'. – David Wohlferd Sep 08 '22 at 01:20
-
1If the user enters a string like 123, that is still a string (series or sequence of bytes or characters) until you do something with that: that something is a like parsing, albeit simple parsing. Parsing can fail so you need a success case and a fail case, if you encounter something not recognized as an integer. – Erik Eidt Sep 08 '22 at 23:42