+ 1
C++
I have a little problem! Suppose that there asked user to input char variable. How to make c++ to recognize entered character as int if it is a digit? What about if entered character is 2 or more digit number? Is there any way to solve this type of problem? If there is any, can you let me know that because I really don't know how to do it!
2 Answers
0
It depends on your input structure, could you give an example?
For single digits you could for example check if the ASCII value matches one of a number. If so, convert and assign it to an integer variable.
0
For example after compiling you're asked to enter anything...
if you enter a letter c++ should print "you entered letter "
Else if you enter number c++ should print "you entered number"
How can I do this type of coding?