How do I check for a blank entry for numerical input in a C++ program? For example, if my input variable is Qty (an int), how do I check to see if the user simply presses Enter without keying in a value for Qty?
Printable View
How do I check for a blank entry for numerical input in a C++ program? For example, if my input variable is Qty (an int), how do I check to see if the user simply presses Enter without keying in a value for Qty?
when you use CIN the program will wait for a value to be entered.
When obtaining input from the user it is often best to get the input as a string and then parse it. If you need numerical input then have a look at atoi() which will transform a string to a number.