I am making a command line program that finds factors of a number that the user enters. At the moment the user could enter something like this: '768r7fg38gf8320rf' which returns an error. I would like to restrict the user so they can only enter numbers (0 - 9). How would I do this?

_Michael_
Recommended Answers
Jump to PostWithout knowing precise details of your environment, it's very hard to say how you would do that.
But it's far simpler just to let the user enter what they like, then validate it.
Jump to PostTo avoid using non-stnadard functions in conio.h, you can use win32 api console functions. Here is how to filter the keys you don't want. This is not the entire program you need, but will get you going so that you can do your own thing with it.
All 5 Replies
Salem 5,265 Posting Sage

_Michael_
mrnutty 761 Senior Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.