I want to make a program that only takes integer. and if someone write any alphabet, then it will ask again for that number.

For Example:

Enter Age:as
Invalid Number

Enter Age:

Recommended Answers

All 3 Replies

You have two options:

  1. Read a line of input, parse it, and determine whether it matches your program's expectations. If not, print an error and request input again until you get what you want.
  2. Use a non-standard, non-portable library to read raw input from the keyboard. With this you can simulate your own simple shell and simply do nothing (as the user sees it) if an invalid character is entered.

Can You Please make a small sample program for me.. PLEASE i am a new programmer.. and don't know anything...

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.