Type checking
-
How to track for char as input while doing addition for integers. If accidentally given char as input how to prevent it from performing addition calculation.
-
How to track for char as input while doing addition for integers. If accidentally given char as input how to prevent it from performing addition calculation.
You can either 1.) Scan each character of the entry before doing anything with it, this is the generic form of a parser. 2.) Try converting it and if you get an error prompt, reloop and ask for entry again. 3.) Look for an error and if found exit program with error notification. Which depends on what the source of the number is and what your goals with your program are. For example if the source of the number is a file not much use prompting and asking for re-entry ... files can't do anything about it :-) So the question comes down as, in the program you are writing what do you think it should do? What is the most elegant and most useful?
In vino veritas