quick question

This is a discussion on quick question within the C Programming forums, part of the General Programming Boards category; 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 ...

  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
    Katy, Texas
    Posts
    2,309
    Because of the way you are using ints. Why aren't you using floats or doubles?
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  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
    Katy, Texas
    Posts
    2,309
    Sorry, not today.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

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

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

    The very first assignment you do, you lose whatever fraction you had.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  7. #7
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    435
    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
    Katy, Texas
    Posts
    2,309
    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.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

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-27-2005, 12:05 AM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 04:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 05:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 12:04 PM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 06:46 PM

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