question for any C++ progammers

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: der.hansPLUGd@LuftHans.com
Date:  
Subject: question for any C++ progammers
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
--
# home.pages.de/~lufthans/ www.Opnix.com
# Knowledge is useless unless it's shared. - der.hans