Thread: quick question

  1. #1
    Banned
    Join Date
    Mar 2008
    Posts
    78

    quick question

    Why is my ceilling allways getting me ZERO as result?

    code: http://pastebin.com/m765144af

    (Dont tell me to use C's ceilling, i'm trying to make one)

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Because of the way you are using ints. Why aren't you using floats or doubles?
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Banned
    Join Date
    Mar 2008
    Posts
    78
    Because i want it to return a Int, can you correct it plz?

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Sorry, not today.
    Mainframe assembler programmer by trade. C coder when I can.

  5. #5
    Banned
    Join Date
    Mar 2008
    Posts
    78
    anyone?

  6. #6
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    I will give you a hint.

    The very first assignment you do, you lose whatever fraction you had.
    Mainframe assembler programmer by trade. C coder when I can.

  7. #7
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    431
    Code:
    int ceiling (double x)
    {
        if (x>0 && x<1)
            return 1;
        else if (x>1 && x<2)
            return 2;
        else if (>2 && x<3)
            return 3;
        //... just keep doing this for every number
        else return (int)x;
    }
    Almost trivial, if you ask me.
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  8. #8
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Quote Originally Posted by NeonBlack View Post
    Code:
    int ceiling (double x)
    {
        if (x>0 && x<1)
            return 1;
        else if (x>1 && x<2)
            return 2;
        else if (>2 && x<3)
            return 3;
        //... just keep doing this for every number
        else return (int)x;
    }
    Almost trivial, if you ask me.
    You forgot the negative numbers.
    Mainframe assembler programmer by trade. C coder when I can.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM