[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

testing for integers

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

649 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