473,473 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Only number not alphabet. how? c++

Hello,

how to do simple code for:

if(alphabet)
output ERROR

because char is int I cannot do like this:
if(sale >= 'a' && sale =< 'z')

because if my sale is 98 it will output error because b is 98.

I want number, not character.
how?

Thank you.
Mar 18 '08 #1
4 3075
ku*******@gmail.com wrote:
how to do simple code for:

if(alphabet)
output ERROR

because char is int I cannot do like this:
if(sale >= 'a' && sale =< 'z')

because if my sale is 98 it will output error because b is 98.

I want number, not character.
how?
See the family of 'std::is...' functions from <cctypeheader.
Something like

if (std::islower(sale) && std::isalpha(sale)) ...

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Mar 18 '08 #2
On 3ÔÂ18ÈÕ, ÏÂÎç10ʱ55·Ö, kundas...@gmail.com wrote:
Hello,

how to do simple code for:

if(alphabet)
output ERROR

because char is int I cannot do like this:
if(sale >= 'a' && sale =< 'z')

because if my sale is 98 it will output error because b is 98.

I want number, not character.
how?

Thank you.
// Enable RTTI and you can use typeid operator to get the type info.
// compile with: /GR /EHsc
#include <iostream>
#include <typeinfo.h>
using namespace std;

int main() {

char a;
int b;
cout << typeid( a ).name() << endl;
cout << typeid( b ).name() << endl;
}
Mar 18 '08 #3
ku*******@gmail.com wrote in news:a6a5021d-b4da-49a8-8016-8b63e90c9e32
@i29g2000prf.googlegroups.com:
Hello,

how to do simple code for:

if(alphabet)
output ERROR

because char is int I cannot do like this:
if(sale >= 'a' && sale =< 'z')
Why not?
because if my sale is 98 it will output error because b is 98.
The if clause above does not output any error :-S
I want number, not character.
how?
Sorry, can't really understand what you want. The char and int types are
both holding numbers in C++ and can be converted easily into each other (if
values fit). It depends on the program if it interprets the values as
numbers or as ASCII character codes. The iostream facility generally
interprets chars as ASCII character codes and ints as numbers, if this is
your concern you should convert the numbers from one type to another.

Post more code if this did not help!

regards
Paavo
Mar 18 '08 #4
On Mar 18, 8:41 pm, Paavo Helde <nob...@ebi.eewrote:
kundas...@gmail.com wrote in news:a6a5021d-b4da-49a8-8016-8b63e90c9e32
@i29g2000prf.googlegroups.com:
how to do simple code for:
if(alphabet)
output ERROR
because char is int I cannot do like this:
if(sale >= 'a' && sale =< 'z')
Why not?
Because lower case characters are not guaranteed to be
contiguous. (Nor are they with EBCDIC.)
because if my sale is 98 it will output error because b is
98.
The if clause above does not output any error :-S
I want number, not character.
Sorry, can't really understand what you want. The char and int
types are both holding numbers in C++ and can be converted
easily into each other (if values fit). It depends on the
program if it interprets the values as numbers or as ASCII
character codes. The iostream facility generally interprets
chars as ASCII character codes and ints as numbers, if this is
your concern you should convert the numbers from one type to
another.
If the question is how to determine if a particular value is
alphabetic or not, there's always:
#include <locale>

if ( std::isalpha( character, std::locale() ) )
or,
#include <cctype >

if ( std::isalpha( static_cast< unsigned char >( character ) ) )
(The first should work for any value in a char
variable---if the type containing the value is not a char, you
need to cast it to one first. The second will work for any
value in the range [0...UCHAR_MAX], or EOF---if the value is in
a char value, you must cast it to unsigned_char first, to ensure
that no negative values occur.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orient�e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S�mard, 78210 St.-Cyr-l'�cole, France, +33 (0)1 30 23 00 34
Mar 19 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Matt | last post by:
I want to check if the user enters alphabet or numbers only in the text box. If the user enters non-alphabet or non-numbers, I should pop up a message and doesn't allow the user to do that. I am...
50
by: The Bicycling Guitarist | last post by:
A browser conforming to HTML 4.0 is required to recognize &#number; notations. If I use XHTML 1.0 and charset UTF-8 though, does &eacute; have as much support as é ? Sometimes when I run...
18
by: OrenFlekser | last post by:
Hi I've posted this message couple of days ago, but I can't find it now, so sorry if you see it twice... Anyways - I have a text box, and I want my users to be able to write only in english...
2
by: deko | last post by:
Can I return the index number of an array if all I have is the element? For example, if I want to index the alphabet, I can put the letters in the array: Dim varLtr As Variant varLtr =...
12
by: one | last post by:
greetings i am just wondering if some expert here can either show me how to do this or point me to the right direction (url... i want to use c# to generate a list of alphabet e.g A B C ... AA...
8
by: Jack Addington | last post by:
I want to scroll through the alphabet in order to scroll some data to the closest name that starts with a letter. If the user hits the H button then it should scroll to the letter closest to H. ...
43
by: Xancatal | last post by:
Hey everybody. I need help on this one. I need to verify that a number entered by a user is not either a negative number (-100.00), or an alphabet (a, b, c, X, Y) as well as other number other than...
3
by: den | last post by:
inner a text element if I want to allow the insertion of only: alphabet's letters a,b,c,.... and A,B,C,... number and this - and this _ and not want space blank and others characters what is...
20
by: geebanga88 | last post by:
HI i have a method that is supose to store the alphabet in an array however dont think that it is being added to the array. public static void GetAlphabet (char alphabet) { int...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.