I want to create a program that takes in integer input from the user and then terminates when the user doesn't enter anything at all (ie, just presses enter). However, I'm having trouble validating the input (making sure that the user is inputting integers, not strings. atoi() won't work, since the integer inputs can be more than one digit.
What is the best way of validating this input? I tried something like the following, but I'm not sure how to complete it:
char input
while( cin>>input != '\n')
{
//some way to check if input is a valid number
while(!inputIsNumeric)
{
cin>>input;
}
}
inputis a pointer. Why are you taking input to it usingcin? I am not sure whether an address can be given that way but address locations are represented in hexa-decimal system and there chances of being alpha-numeric.for(cin>>input; input != '\n'; cin >>input)