Solved

testing for integers

Posted on 2000-04-30
1
211 Views
Last Modified: 2010-04-02
Hi, I want to prompt the user for a data of type double.  But if it is an integer, I would do want to do something extra with it.  How do seperate integers from those that are not?  I try to make a logorithm using mods, divisions, but still end up in the mud.  Please help.
0
Comment
Question by:x_octane_x
1 Comment
 
LVL 22

Accepted Solution

by:
nietod earned 30 total points
ID: 2764418
double D;
int i;

cout << "enter a number ";
cin >> D;

i = D; // truncate to an integer.  (i.e. 2.5 becomes 2.)

if (i == D) // if D was an integer, then
  // do something special.

Let me know if you have any questions.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question