1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Changing a double value to an integer value in c++

  1. Dec 23, 2012 #1
    1. The problem statement, all variables and given/known data
    I'm making a program which will convert mph to minutes and seconds per mile. For example my program will take 6.5 mph and convert it to 9 minutes and 13.8 seconds per mile. But being new to programming I don't know how to convert a double value to an int value (I believe its called casting). So the book gives me the following formula/ equation
    intValue = static_cast<int>(dblVal);

    if I have the variable speed = 9.23 (thats 6.5 mph converted to miles per min) and I want to store the integer part in another variable called speedM , where in the above equation do I put speed and speedM?

    2. Relevant equations



    3. The attempt at a solution
     
  2. jcsd
  3. Dec 23, 2012 #2

    Dick

    User Avatar
    Science Advisor
    Homework Helper

    Look at the variable names! dblVal will be your double. intValue will be your int. And in a case like this you don't even need to explicitly cast them. speedM=speed will work fine. It will implicitly cast. Don't you have a C++ compiler you can use to try these things out?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Changing a double value to an integer value in c++
Loading...