473,320 Members | 1,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

checking for TYPE INT

JC
Hello,

I was wondering if there is a way I can check for the TYPE of answer I
receive from a user

For example I'm writing a program that requires the user to enter a integer
(TYPE INT)
if someone enters a type CHAR, or any other type other than INT, I want to
display a message...

example code.

int num,

cout <<"\n please enter a number to add to the list";
cin >> num; // I want to check here to make sure they enter a INT...
I do not want to continue with the program is not INT.

Thank you for all of your help!
JC
Jul 19 '05 #1
3 7820
JC wrote:
Hello,

I was wondering if there is a way I can check for the TYPE of answer I
receive from a user

For example I'm writing a program that requires the user to enter a integer
(TYPE INT)
if someone enters a type CHAR, or any other type other than INT, I want to
display a message...

example code.

int num,

cout <<"\n please enter a number to add to the list";
cin >> num; // I want to check here to make sure they enter a INT...
I do not want to continue with the program is not INT.

Thank you for all of your help!


See:

http://www.parashift.com/c++-faq-lit....html#faq-15.3

(In fact, reading the whole section would be a good idea. Come to
think of it, you *really* should have read the FAQ *before* posting
a question.)

HTH,
--ag

--
Artie Gold -- Austin, Texas
Oh, for the good old days of regular old SPAM.

Jul 19 '05 #2
I just encountered the very same situation and am greatful at your response to
JC's question on 'Checking for int'. Your solution is much easier than the
approach I was about to take. This newsgroup is ok! I'll be reading the FAQ's
every chance I get!

Your guidance is appreciated!

JB
Jul 19 '05 #3
JC
Thank you Artie for the solution.
I'll give this a try

"Artie Gold" <ar*******@austin.rr.com> wrote in message
news:3F**************@austin.rr.com...
JC wrote:
Hello,

I was wondering if there is a way I can check for the TYPE of answer I
receive from a user

For example I'm writing a program that requires the user to enter a integer (TYPE INT)
if someone enters a type CHAR, or any other type other than INT, I want to display a message...

example code.

int num,

cout <<"\n please enter a number to add to the list";
cin >> num; // I want to check here to make sure they enter a INT... I do not want to continue with the program is not INT.

Thank you for all of your help!


See:

http://www.parashift.com/c++-faq-lit....html#faq-15.3

(In fact, reading the whole section would be a good idea. Come to
think of it, you *really* should have read the FAQ *before* posting
a question.)

HTH,
--ag

--
Artie Gold -- Austin, Texas
Oh, for the good old days of regular old SPAM.

Jul 19 '05 #4

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

Similar topics

2
by: Tobiah | last post by:
Hi, I have a module that defines a few classes. one of them is Event. If I do: e = Event() print type(e) I get back:
12
by: Aaron Watters | last post by:
I'm doing a heart/lung bypass procedure on a largish Python program at the moment and it prompted the thought that the methodology I'm using would be absolutely impossible with a more "type safe"...
3
by: George Sakkis | last post by:
Explicit type checking is not typically seen in Python code, and usually that's not a big problem; most typing errors are likely to raise a TypeError or AttributeError sooner than later. There are...
5
by: Tongu? Yumruk | last post by:
I have a little proposal about type checking in python. I'll be glad if you read and comment on it. Sorry for my bad english (I'm not a native English speaker) A Little Stricter Typing in Python...
16
by: gaudetteje | last post by:
I just read in the 'What's New in Python 2.4' document that the None data type was converted to a constant: http://python.org/doc/2.4/whatsnew/node15.html """ # None is now a constant; code...
6
by: Web Developer | last post by:
Hi, I come across the term "type checking" very often in my readings on C++, and have never heard it in Java. Besides the simplistic answer that it checks the "type", what more does it mean? ...
8
by: Robert Mark Bram | last post by:
Howdy All! How can you tell the type of an object? I am not talking about using "typeof" .. I am talking about being able to determine if an object is a Date or String .... Thanks for...
20
by: Xiaoshen Li | last post by:
Hi, I am reading the book "Concepts of programming languages" by R. W. Sebesta. He said: "One of the most important reasons why C is both liked and disliked is its lack of complete type...
3
by: Brian Henry | last post by:
I know i read this somewhere before... If I have an object of unknown type how can I say is this a datarow? or is this an integer? then do something based on that... i thought IS worked for that...
4
by: Patient Guy | last post by:
Does anyone have any coding rules they follow when doing argument checking? When arguments fail during check, do you return from the call with an ambiguous return value, or do you throw...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.