|
From: Ioannis V. <no...@ya...> - 2001-12-22 15:48:59
|
Your code was not proper ANSI C++ too. Your code corrected and fully
portable:
#include <cstdlib>
#include <cctype>
#include <iostream>
int main()
{
using namespace std;
unsigned char number;
cout << "\n\tInput number or letter: ";
cin >> number;
if(isalnum(number))
{
cout << "\n\tIt is alnum" <<endl;
if(isdigit(number))
cout << "\tIt is digit" <<endl;
else if(isalpha(number))
{
cout << "\tIt is alpha" << endl;
if(islower(number))
cout << "\tIt is lower"<< endl;
}
}
cout << endl;
system("PAUSE");
}
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.f2s.com
* Alternative URL: http://run.to/noicys
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Exuss Draugas
> Sent: Saturday, December 22, 2001 10:11 AM
> To: Dev...@li...
> Subject: [Dev-C++] Checking data type
>
>
>
>
> Hi, All! :)
>
> How to check input data type from the console? For example, I need
> only number, and how to check that some letters wasn't entered?
>
> This code shows doesn't work for me, if I try to enter some number,
> it shows a zero in every condition. ://
>
> #include <stdlib.h>
> #include <ctype.h>
> #include <iostream.h>
>
> void main()
> {
>
> int number;
> cout << "\n\tInput number or letter: ";
> cin >> number;
> cout << "\n\tIs alnum?: " << isalnum(number) << endl;
> cout << "\tIs digit?: " << isdigit(number) << endl;
> cout << "\tIs alpha?: " << isalpha(number) << endl;
> cout << "\tIs lower?: " << islower(number) << endl;
> cout << endl;
> system("PAUSE");
> }
>
> Are there other way to check what was entered from console, digital
> number or text ???
>
> Thanx,
>
> Exuss :)
>
>
>
> --
> Nemokama el.pasto dezute - http://webmail.delfi.lt/
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|