Thread: Multiply two float number

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    116

    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
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    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
    6,815
    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%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    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, 03: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, 11:10 AM