You are here:

C++/Knowing when a digit is a digit and a letter is a letter


I am a beginning C++ student. I am writing
programs that just take numbers without identify
them as numbers. I type a letter and my program
crashed.  So, I want to know the code to place
in my program to let the program that I have written to check for either a digit or letter
at the time of asking at the prompt. If not a
digit I want it to say not a digit please enter
a digit(s) and vice versa if not a letter please
enter a letter(s)


humm an interesting situation :)

There is a function "isdigit()" defined by the standard C++.
it is used as this .


int a ;
cin >> a ;

if ( isdigit ( a) )
// do somethging

this function return ture if'a' is a digit and else other wise. Try this out.

Hope this helps.



All Answers

Answers by Expert:

Ask Experts




I can answer any question about functions,pointers,structures,object oriented programming basics of classes and data structures.My strong field is structured programming.


I have got 2 years experiece under C . I am able to answer about the structured concepts pointers to a little extent,OOP concepts. I have also experience in data Strucutres like Linked List, Stacks , Queues, Heaps, B Trees, Red Black Trees. I will try to satisfy with my knowledge. I am the Student of an expert here Martin, what i have learnt today, i just owe my every knowledge to him. He is the greatest.

©2017 All rights reserved.