Solved

testing for integers

Posted on 2000-04-30
1
212 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

732 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