Solved

testing for integers

Posted on 2000-04-30
1
208 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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now