| | |
Validation Program
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2006
Posts: 2
Reputation:
Solved Threads: 0
How can i make a program in c++ which accept only the following:
1) Any positive number.
2)Character from [A to Z] -in upper case.
Note: this program won't work as desired because idon't know how to get the ASCII of any number or character-by using int().
#include<iostream.h>
void main()
{
int a;
cout<<"Enter either number or character to check it's availability "<<endl;
cin>>a;
if(int ('a')>=65 && int('a')<=90) // int('a') always will be 97-the ASCII of character a.
cout<<"It's valid"<<endl;
1) Any positive number.
2)Character from [A to Z] -in upper case.
Note: this program won't work as desired because idon't know how to get the ASCII of any number or character-by using int().
#include<iostream.h>
void main()
{
int a;
cout<<"Enter either number or character to check it's availability "<<endl;
cin>>a;
if(int ('a')>=65 && int('a')<=90) // int('a') always will be 97-the ASCII of character a.
cout<<"It's valid"<<endl;
Giving you the solution is easier than trying to understand what you are saying.
C++ Syntax (Toggle Plain Text)
#include<iostream> using namespace std; int main() {<blockquote>char a; cout<<"Enter either number or character to check it's availability "<<endl; cin>>a; if( ( 'a' <= a && a <= 'z' ) ||( 'A' <= a && a <= 'Z' )|| ( '0' <= a && a <= '9' ) ) {<blockquote>cout<<"It's valid"<<endl;</blockquote>} return 0;</blockquote>}
>idon't know how to get the ASCII of any number or character
char is a little int, so you don't need to do anything special to get the numeric value of the character (ASCII isn't always used). However, since ASCII isn't always used, and not all character sets are required to have contiguous values for anything but the numeric digit characters, you're much better off using isalpha and isdigit from <cctype>:
char is a little int, so you don't need to do anything special to get the numeric value of the character (ASCII isn't always used). However, since ASCII isn't always used, and not all character sets are required to have contiguous values for anything but the numeric digit characters, you're much better off using isalpha and isdigit from <cctype>:
C++ Syntax (Toggle Plain Text)
if ( std::isdigit ( c ) || std::isalpha ( c ) ) std::cout<<"Valid";
I'm here to prove you wrong.
![]() |
Similar Threads
- Another Hacktool.Rootkit (Viruses, Spyware and other Nasties)
- For Kali2005: HackTool.Rootkit - Help Needed (Viruses, Spyware and other Nasties)
- Another hacktool.rootkit virus (Viruses, Spyware and other Nasties)
- IE works fine but Firefox doesn't display tables! (HTML and CSS)
- VC++ Stage 3 project help me!!!!!!1 (C++)
- Something showling my system down (hijackthis log incl) (Viruses, Spyware and other Nasties)
- hijackthis log...I need help please (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: Data loss in Type Conversion.
- Next Thread: HELP!!! Weird problem...
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg simple sorting string strings temperature template text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






