473,473 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

isnumeric

Hello,

I would like to know if the function IsNumeric requires a header like
#include <iostream> to be functionnal

thanks

ken
Jul 22 '05 #1
14 40098
On Wed, 2 Jun 2004 21:26:56 -0400, "Kenny" <le******@yah00.c0m> wrote:
Hello,

I would like to know if the function IsNumeric requires a header like
#include <iostream> to be functionnal


There's no function by that name in either the C or C++ libraries.
Actually, I don't know of /any/ standard library functions whatsoever that
have capital letters in their names.

If you're asking about the character classification functions such as
isdigit(), isalpha(), et. al., then for C++ you should include <cctype>.
-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #2
that did not work ,
do you know the parameter setting of that calling function ?

K
Jul 22 '05 #3
Kenny wrote:

that did not work ,
do you know the parameter setting of that calling function ?


Kenny. Please make it a habit of yours to *not* post:
'It doesn't work'

Tell us *what* the problem is: Do you get a compiler
error? Do you get a runtime error? Does the program not
behave the way you want it to?

Also: post a small code snippet such that we can see what
you have tried and what gave you troubles. Ideally you post
a small, *complete* program, such that we can cut&paste
it into our development environments and try the very
same as you did.

If you don't do this then all that is left to us is: guess
And guessing is never a good way to figure out technical
problems.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #4
Kenny. Please make it a habit of yours to *not* post:
'It doesn't work'

Tell us *what* the problem is: Do you get a compiler
error? Do you get a runtime error? Does the program not
behave the way you want it to?

Also: post a small code snippet such that we can see what
you have tried and what gave you troubles. Ideally you post
a small, *complete* program, such that we can cut&paste
it into our development environments and try the very
same as you did.

If you don't do this then all that is left to us is: guess
And guessing is never a good way to figure out technical
problems.

ok here is the code

cout << " Your choice please: ";
cin >> choice;
if (isnumeric(choice) == true){


Jul 22 '05 #5
Kenny wrote:
that did not work ,
do you know the parameter setting of that calling function ?

K


#include <iostream> // for cout
#include <cstdlib> // for EXIT_SUCCESS
#include <ctypes> // for isdigit

using std::cout;
using std::endl;
using std::isdigit;

int main(void)
{
cout << "Is '5' a digit (numeric)?" << endl;
cout << isdigit('5') << endl;
cout << "\nIs 'Z' a digit?" << endl;
cout << isdigit('Z') << endl;
return EXIT_SUCCESS;
}

Much can be learned by reading a C++ reference book
and the FAQ.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 22 '05 #6
On Thu, 3 Jun 2004 09:27:31 -0400, "Kenny" <le******@yah00.c0m> wrote:
ok here is the code

cout << " Your choice please: ";
cin >> choice;
if (isnumeric(choice) == true){


Are you just inventing function names and hoping they work? Start with a
library reference of some kind, and examine your options. Here's one I
found in 30 seconds of Googling ("C library"):
http://www.acm.uiuc.edu/webmonkeys/book/c_guide/

-leor


--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #7

ok here is the code

cout << " Your choice please: ";
cin >> choice;
if (isnumeric(choice) == true){


Are you just inventing function names and hoping they work? Start with a
library reference of some kind, and examine your options. Here's one I
found in 30 seconds of Googling ("C library"):
http://www.acm.uiuc.edu/webmonkeys/book/c_guide/


I guess you did not try the term 'isnumeric' in google I just did not
find a page where it was talking about how to call it in c++, just VB and
C#.

Jul 22 '05 #8

"Thomas Matthews" <Th****************************@sbcglobal.net> wrote in
message news:eU*****************@newssvr33.news.prodigy.co m...
Kenny wrote:
that did not work ,
do you know the parameter setting of that calling function ?

K


#include <iostream> // for cout
#include <cstdlib> // for EXIT_SUCCESS
#include <ctypes> // for isdigit

using std::cout;
using std::endl;
using std::isdigit;

int main(void)
{
cout << "Is '5' a digit (numeric)?" << endl;
cout << isdigit('5') << endl;
cout << "\nIs 'Z' a digit?" << endl;
cout << isdigit('Z') << endl;
return EXIT_SUCCESS;
}

Much can be learned by reading a C++ reference book
and the FAQ.

I guess my book from Walter Savitch , absolute c++ is not so good.

Jul 22 '05 #9
Kenny wrote:
Kenny. Please make it a habit of yours to *not* post:
'It doesn't work'

Tell us *what* the problem is: Do you get a compiler
error? Do you get a runtime error? Does the program not
behave the way you want it to?

Also: post a small code snippet such that we can see what
you have tried and what gave you troubles. Ideally you post
a small, *complete* program, such that we can cut&paste
it into our development environments and try the very
same as you did.

If you don't do this then all that is left to us is: guess
And guessing is never a good way to figure out technical
problems.

ok here is the code

cout << " Your choice please: ";
cin >> choice;
if (isnumeric(choice) == true){


OK.
And what is the problem with this code?

Note: isnumeric() isn't one of the standard functions
So you must have written it by yourself. What this
function exactly has to look like is dependent on the
data type of choice.

So what is choice?
Where is the implementation of isnumeric()?
and last but not least: Which error message did you
get from your compiler.
Could it be that you wanted isdigit() instead of isnumeric()
(Note: isdigit() checks a *single* character if it represents
a numerical digit, not a whole string. But using this function
it is easy to write a function isNumeric which does the whole
thing on a complete string).
I know all of this may sound childish to you. But remember:
*You* sit in front of your computer. *You* write the program.
*You* see the error messages from your compiler. If we try
to help you, we can only use what *you* tell us. If you
call your doctor and cry: "Help" I am sure your doctor would
do the very same: Ask for details. If you are a good patient
you wouldn't let your doctor ask you for everything but provide
him with all you know about your problem in the first place.
We *want* to help you, that's why we are here and answer questions.
But we also expect people seeking for help to coorporate.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #10
Kenny wrote:
>
ok here is the code

cout << " Your choice please: ";
cin >> choice;
if (isnumeric(choice) == true){


Are you just inventing function names and hoping they work? Start with a
library reference of some kind, and examine your options. Here's one I
found in 30 seconds of Googling ("C library"):
http://www.acm.uiuc.edu/webmonkeys/book/c_guide/


I guess you did not try the term 'isnumeric' in google I just did not
find a page where it was talking about how to call it in c++, just VB and
C#.


AS Leor has pointer out already, there is *no* function called
isnumeric() in standard C or standard C++.
Depending on what you actually want you have to
* use isdigit() out of the box
* write your own function isnumeric()

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #11
On Thu, 3 Jun 2004 09:57:17 -0400, "Kenny" <le******@yah00.c0m> wrote:
>>
>ok here is the code
>
> cout << " Your choice please: ";
> cin >> choice;
> if (isnumeric(choice) == true){
>
Are you just inventing function names and hoping they work? Start with a
library reference of some kind, and examine your options. Here's one I
found in 30 seconds of Googling ("C library"):
http://www.acm.uiuc.edu/webmonkeys/book/c_guide/


I guess you did not try the term 'isnumeric' in google


You guess wrong.
I just did not
find a page where it was talking about how to call it in c++, just VB and
C#.
Hello!!
-leor



--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #12

"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message
news:40***************@gascad.at...
Kenny wrote:
Kenny. Please make it a habit of yours to *not* post:
'It doesn't work'

Tell us *what* the problem is: Do you get a compiler
error? Do you get a runtime error? Does the program not
behave the way you want it to?

Also: post a small code snippet such that we can see what
you have tried and what gave you troubles. Ideally you post
a small, *complete* program, such that we can cut&paste
it into our development environments and try the very
same as you did.

If you don't do this then all that is left to us is: guess
And guessing is never a good way to figure out technical
problems.

ok here is the code

cout << " Your choice please: ";
cin >> choice;
if (isnumeric(choice) == true){


OK.
And what is the problem with this code?

Note: isnumeric() isn't one of the standard functions
So you must have written it by yourself. What this
function exactly has to look like is dependent on the
data type of choice.

So what is choice?
Where is the implementation of isnumeric()?
and last but not least: Which error message did you
get from your compiler.
Could it be that you wanted isdigit() instead of isnumeric()
(Note: isdigit() checks a *single* character if it represents
a numerical digit, not a whole string. But using this function
it is easy to write a function isNumeric which does the whole
thing on a complete string).
I know all of this may sound childish to you. But remember:
*You* sit in front of your computer. *You* write the program.
*You* see the error messages from your compiler. If we try
to help you, we can only use what *you* tell us. If you
call your doctor and cry: "Help" I am sure your doctor would
do the very same: Ask for details. If you are a good patient
you wouldn't let your doctor ask you for everything but provide
him with all you know about your problem in the first place.
We *want* to help you, that's why we are here and answer questions.
But we also expect people seeking for help to coorporate.

Choice is an int, I read somewhere that isnumeric is a built in function ,
just like strcpy . Is numeric should return true if it is a numeric value
and false other wise. so isnumeric is not in c++ , just in c ??

K

Jul 22 '05 #13
Kenny wrote:

"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message
news:40***************@gascad.at...
Kenny wrote:

> Kenny. Please make it a habit of yours to *not* post:
> 'It doesn't work'
>
> Tell us *what* the problem is: Do you get a compiler
> error? Do you get a runtime error? Does the program not
> behave the way you want it to?
>
> Also: post a small code snippet such that we can see what
> you have tried and what gave you troubles. Ideally you post
> a small, *complete* program, such that we can cut&paste
> it into our development environments and try the very
> same as you did.
>
> If you don't do this then all that is left to us is: guess
> And guessing is never a good way to figure out technical
> problems.
>
ok here is the code

cout << " Your choice please: ";
cin >> choice;
if (isnumeric(choice) == true){
OK.
And what is the problem with this code?

Note: isnumeric() isn't one of the standard functions
So you must have written it by yourself. What this
function exactly has to look like is dependent on the
data type of choice.

So what is choice?
Where is the implementation of isnumeric()?
and last but not least: Which error message did you
get from your compiler.
Could it be that you wanted isdigit() instead of isnumeric()
(Note: isdigit() checks a *single* character if it represents
a numerical digit, not a whole string. But using this function
it is easy to write a function isNumeric which does the whole
thing on a complete string).
I know all of this may sound childish to you. But remember:
*You* sit in front of your computer. *You* write the program.
*You* see the error messages from your compiler. If we try
to help you, we can only use what *you* tell us. If you
call your doctor and cry: "Help" I am sure your doctor would
do the very same: Ask for details. If you are a good patient
you wouldn't let your doctor ask you for everything but provide
him with all you know about your problem in the first place.
We *want* to help you, that's why we are here and answer questions.
But we also expect people seeking for help to coorporate.


Choice is an int,


Then I am afraid: What you want to do cannot be done.
An int holds a number per definition! That's what it is for.
I read somewhere that isnumeric is a built in function ,
just like strcpy . Is numeric should return true if it is a numeric value
and false other wise. so isnumeric is not in c++ , just in c ??


Not even there.
An int always holds a number! That's the definition of int. You can't
store "Hello world" in an int.

What you *want* to do is something completely different:
You want to check the users input if the user entered a number.
Well if you use

int choice;

cin >> choice;

Then the user has no other possibility: He *has* to enter a number
or otherwise the input stream would simply refuse to accept the
users input and go into a fail state.

There are 2 possibilities you can cope with that problem:
* detect that the stream has gone into a fail state, clear
that fail state and discard all pending input

* Don't read into an int. Read into a string instead. This
way the user can enter what he wants, a string can accept
everything. Then your part begins. You have to check if
what the user has entered is what you expected him to enter
and react accordingly.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #14
Kenny wrote:

[snip]
Choice is an int, I read somewhere that isnumeric is a built in function ,
just like strcpy . Is numeric should return true if it is a numeric value
and false other wise. so isnumeric is not in c++ , just in c ??

K


Sorry Kenny, but isnumeric is not in C either.

Check your book carefully. Many authors write primitive
functions in other chapters and reference them throughout
the book.

The easiest method to test if an input value is numeric,
is to use the extraction operator, ">>" and read into
an integral (i.e. unsigned or signed integer) variable.
If the stream state is good, then the value is numeric.

Here is a common idiom:
unsigned int option_num;
do
{
// Display numeric options,
// such as 1. Do Something.
cout.flush(); // For synchronization.
cin >> option_num;
} while (cin.fail() || (option < 1) || ...);
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 22 '05 #15

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

Similar topics

8
by: eje | last post by:
IsNumeric(value) should return false if value "can not be successfully converted to a Double." Instead I get the following error message: "Input string was not in a correct format." I use the...
4
by: Eugene Anthony | last post by:
I have received the following feedback for the two functions bellow: "The ISNUMERIC test is WORTHLESS for checking for an INT value, because ISNUMERIC will happily accept DOUBLE values, such as...
8
by: John Bowman | last post by:
Hello, Does anyone have a good/reliable approach to implementing an IsNumeric() method that accepts a string that may represent a numerical value (eg. such as some text retrieved from an XML...
3
by: martin | last post by:
Hi, is there a dotnet function (other than the old isnumeric from VB) to check whether an object is numeric or not. also I notice that all the old vb functions such as split / isnumeric /...
7
by: Nathan Truhan | last post by:
All, I think I may have uncovered a bug in the IsNumeric function, or at least a misunderstanding on functionality. I am writing a Schedule Of Classes Application for our campus and have a...
8
by: moondaddy | last post by:
What's the .net framework equivalent of the vb function isnumeric? If there isn't one, how can I test a string variable to see if its a number or not? I don't want to use isnumeric if possible ...
12
by: sck10 | last post by:
Hello, I am trying to determine if a value is NOT numeric in C#. How do you test for "Not IsNumeric"? protected void fvFunding_ItemInserting_Validate(object sender, FormViewInsertEventArgs...
12
by: Paul | last post by:
Hi, I am trying to check a string to see if it's first 3 characters are numeric and if they are, to replace those 3 characters with something else. I've tried this but nothing happens... ...
17
by: MLH | last post by:
I have tested the following in immed window: ?isnumeric(1) True ?isnumeric(1.) True ?isnumeric(1.2) True ?isnumeric(1.2.2)
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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.