question for any C++ progammers
der.hans
PLUGd@LuftHans.com
Wed, 16 Aug 2000 23:18:25 -0700 (MST)
Am 16. Aug, 2000 schwäzte Eric Samson so:
> I am pretty new to C++, compiling, etc., I really want to learn this
> stuff... I am trying to figure out how to validate input from a user to
> make it accept only positive numeric values. I was using a while loop to
> check it, but when the user enters an alpha character, I get stuck in the
> loop of death, I am sure many of you have experienced this. I asked my
dig = getchar();
while (isdigit(dig)) {
do_stuff;
dig = getchar();
}
You might want to also allow room for a dot, so as to check for decimals,
but I think this does the basics of what you want. It's been several years
since I've done any c/c++, though.
> instructor how to do this, but he said that he wasn't sure. would an if
> statement nested in a while loop solve my problem??
>
> Sorry about these newbie questions, but it's my second week in the class.. :
No prob. You might want to join the devel list, though. That's a more
appropriate place for devel questions.
ciao,
der.hans
--
# der.hans@LuftHans.com home.pages.de/~lufthans/ www.Opnix.com
# Knowledge is useless unless it's shared. - der.hans