Validation Program

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2006
Posts: 2
Reputation: Sun is an unknown quantity at this point 
Solved Threads: 0
Sun Sun is offline Offline
Newbie Poster

Validation Program

 
0
  #1
Mar 22nd, 2006
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;
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Validation Program

 
0
  #2
Mar 22nd, 2006
Get the input as a char and then try validating it's ascii code.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 2
Reputation: Sun is an unknown quantity at this point 
Solved Threads: 0
Sun Sun is offline Offline
Newbie Poster

Re: Validation Program

 
0
  #3
Mar 22nd, 2006
In that way i will reserve abig string to sore any length for input because idon't know how to store characters in dynamic array at the first of program so in that way the program will take a useless space
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Validation Program

 
0
  #4
Mar 22nd, 2006
Giving you the solution is easier than trying to understand what you are saying.
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {<blockquote>char a;
  5. cout<<"Enter either number or character to check it's availability "<<endl;
  6. cin>>a;
  7. if( ( 'a' <= a && a <= 'z' ) ||( 'A' <= a && a <= 'Z' )|| ( '0' <= a && a <= '9' ) )
  8. {<blockquote>cout<<"It's valid"<<endl;</blockquote>}
  9. return 0;</blockquote>}
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Validation Program

 
0
  #5
Mar 22nd, 2006
>Giving you the solution is easier than trying to understand what you are saying.


I second that! Sometimes I have no idea what they mean?
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,771
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 743
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Validation Program

 
0
  #6
Mar 22nd, 2006
>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>:
  1. if ( std::isdigit ( c ) || std::isalpha ( c ) )
  2. std::cout<<"Valid";
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC