faqts : Computers : Programming : Languages : C++

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

6 of 27 people (22%) answered Yes
Recently 4 of 10 people (40%) answered Yes

Entry

How do I write a IsDigit() function which will output the number as Digit(0-9) or Not digit to scree

May 27th, 2003 02:36
Colin Thomsen, Lam Ho,


Assuming you have a character as the input, the function can be 
something like:
#include <iostream>
void IsDigit(char c)
{
    if ((c >= '0') && (c <= '9'))
        std::cout << "Digit(" << c << ")"<< std::endl;
    else
        std::cout << "Not digit" << std::endl;
}
int main()
{
    IsDigit('a');
    IsDigit('3');
}