Write a C++ program that reads a character and tells the user if it is a letter (‘a’…’z’, ’A’…’Z’), a digit (‘0’…’9’), a punctuation mark (‘.’ … ‘!’), or special character (other than these). The problem is that whatever I type, it prints "This is a puncuation mark!"
#include <iostream>
#include<windows.h>
usingnamespace std;
int main()
{
char c;
cout << "Enter a character : ";
cin>>c;
if (((int)c>=33)&&((int)c>=47))
{
cout<<"This is a puncuation mark!"<<endl;
}
elseif (((int)c>=65 )&&((int)c<=90)||((int)c>=97)&&((int)c<=122))
{
cout<<"This is a letter!"<<endl;
}
elseif (((int)c>=48)&&((int)c>=57))
{
cout<<"This is a digit!"<<endl;
}
else
{
cout<<"This is a special character!"<<endl;
}
system("pause");
return 0;
}
#include <iostream>
#include <windows.h>
usingnamespace std;
int main()
{
char c;
cout << "Enter a character : ";
cin>>c;
if (((int)c>=33)&&((int)c<=47))
{
cout<<"This is a puncuation mark!"<<endl;
}
elseif ((((int)c>=65 )&&((int)c<=90))||(((int)c>=97)&&((int)c<=122)))
{
cout<<"This is a letter!"<<endl;
}
elseif (((int)c>=48)&&((int)c<=57))
{
cout<<"This is a digit!"<<endl;
}
else
{
cout<<"This is a special character!"<<endl;
}
system("pause");
return 0;
}
Enter a character : a
This is a letter!
Enter a character : 5
This is a digit!
Enter a character : :
This is a special character!
Oh I'm sorry I thought it only worked with numbers.. I must admit that in the beginning I was confused, but now I looked over ascii codes and I understood. Btw thanks the program is great! :))