Thread: problem with floats

  1. #1
    Registered User
    Join Date
    Sep 2006

    problem with floats

    i'm having a problem with floats.

    int a, b;
    float percentage;
    // ...
    if (a == b)
    else {
    	percentage = a/(a+b);
    	// check here
    and set bar is defined like this:

    setbar(float percentage);
    but percentage is never a float. if i check it right after i set it (the comment "check here") or within the function setbar, it's either 0 or 1, like it's just an int. the only time it works is if a==b, in which case i tell it to pass 0.5 as the argument. The one thing i notice is that whenever b != 0, percentage is always 0, leading to the conclusion that a/(a+b) is doing the same thing as (int)(a/(a+b))

    what am i doing wrong?

  2. #2
    ... kermit's Avatar
    Join Date
    Jan 2003
    Maybe this would be of some help to you.

  3. #3
    Registered User
    Join Date
    Sep 2006
    thanks, i finally got it to work.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  3. problem with floats in conditional statements
    By Desolation in forum C Programming
    Replies: 3
    Last Post: 07-08-2006, 01:56 AM
  4. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM