Thread: Multiplication is not right.

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    158

    Multiplication is not right.

    Basicallly i'm doing a conversion to meters per second


    double mps=(1000/3282)*(5280/230)

    the answer should be 7.2 meters per second but the output displays it as 0.00000000000 meters per second.

    What is wrong here? Does the program not recognize numbers that are less than one?

    also when i printf it i use %lf. So that should take care of a potential error.

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    You're doing division with integers, so the answer is truncated to an integer value. Make at least one value in each division expression a float/double to get the correct result.

    Code:
    double mps=(1000/3282.0)*(5280/230.0);

  3. #3
    Registered User
    Join Date
    Oct 2012
    Posts
    158
    Wow i'm so stupid haha.

    thank you matticus

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    You're welcome. It's an easy mistake to make. You're not stupid, especially if you've gained a little more experience from this.

  5. #5
    Registered User
    Join Date
    Oct 2012
    Posts
    158
    Definitely!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. multiplication without * & +
    By gourabbanik05 in forum C Programming
    Replies: 10
    Last Post: 08-31-2010, 12:17 AM
  2. Multiplication
    By GReaper in forum C++ Programming
    Replies: 1
    Last Post: 05-29-2010, 10:39 PM
  3. Zero multiplication
    By Kempelen in forum C Programming
    Replies: 13
    Last Post: 05-09-2009, 08:44 AM
  4. Help me find a multiplication toy.
    By QuestionC in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 08-24-2007, 12:27 PM
  5. Multiplication in GCC 2.953
    By Durafei in forum C Programming
    Replies: 2
    Last Post: 05-01-2003, 04:48 PM