Quote:
Originally posted by Aki
I'm making a text based adventure game in C++. Sometimes it asks you to enter an integer, and if you enter a letter the game will get screwed up... so I was looking for a way to fix this and I found this:
Code:
int integer()
{ char inputdata[100];
cin >> inputdata;
return atoi(inputdata);
}
The only problem with this is that if you enter a character instead of a number, it will interpret it as 0, I just want it to say. "Invalid character" or something and ask you to input an actual number... anyway I can fix this?
Here's what I'd do. Prompt for an integer, but store what the user enters into an array of characters. Then, search through the array looking for digits. You can use this: