Multiply two float number

This is a discussion on Multiply two float number within the C++ Programming forums, part of the General Programming Boards category; I have a small problem with float number in C. It doesn't work as I think. This is my code: ...

  1. #1
    hqt
    hqt is offline
    Registered User
    Join Date
    Aug 2011
    Posts
    115

    Question Multiply two float number

    I have a small problem with float number in C. It doesn't work as I think. This is my code:
    Code:
    float a,b,c;
    cin>>a>>b;
    c=a*(float)b;
    cout<<c;
    with a=5.6 and b=2.4. c=0. I know there's a problem with my float processing. So, who can help me please.

    thanks

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,522
    What do you mean it doesn't work as you think? I don't know what you're talking about.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    5,827
    Try giving a small but complete code sample, and a description of the actual input.

    More than likely, the problem is in code that you haven't posted.
    Right 98% of the time, and don't care about the other 3%.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,261
    Quote Originally Posted by hqt View Post
    I have a small problem with float number in C. It doesn't work as I think. This is my code:
    Code:
    float a,b,c;
    cin>>a>>b;
    c=a*(float)b;
    cout<<c;
    with a=5.6 and b=2.4. c=0. I know there's a problem with my float processing. So, who can help me please.

    thanks
    Sorry but that code does work, at least on any proper compiler. (Turbid Crap doesn't count)
    i.e. It will not produce a result of zero with the supplied inputs.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to multiply number elements in a string?
    By david.jones in forum C Programming
    Replies: 1
    Last Post: 05-04-2011, 05:50 AM
  2. float number division
    By hoistyler in forum C Programming
    Replies: 6
    Last Post: 01-14-2009, 02:13 AM
  3. Triming a float number
    By RocketMan in forum C Programming
    Replies: 3
    Last Post: 10-01-2008, 08:31 AM
  4. Float number and sendmessage
    By chris1985 in forum C Programming
    Replies: 1
    Last Post: 06-07-2005, 09:28 PM
  5. testing if a number is a float
    By UnknownImage in forum C Programming
    Replies: 11
    Last Post: 02-13-2003, 10:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21