?
Solved

testing for integers

Posted on 2000-04-30
1
Medium Priority
?
217 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 120 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 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.
Suggested Courses

770 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