Lyle Ladeira writes:
i would like to know if someone can please help me.
i would like to know how to validate characters so that the user would not
be able to enter numbers into a characters field.
The way that is usually recommended is to get the entire line, perhaps using
getline(), see if a suitable number is in the line, and then do your own
conversion. The easiest way is probably to use <cstdlib> functions such as
strtod() and strtol(); although you can do this with "pure" C++ techniques
too. If you find a nice number, go on. Otherwise ask the user to reenter
the entire line.
A second way is to read as though you expect the user to do a proper entry
and then clear up the mess created in the stream if he doesn't. You must
clear the fail state and empty the buffer, in *that order*. see
ios::clear() and istream::ignore(). Then ask the user to try again.
The first way is probably easier and you may learn more of long term
interest that way, too.