Thread: ceil question

  1. #1
    bignood
    Join Date
    Sep 2005
    Posts
    33

    ceil question

    OK here is my program

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #include <math.h>
    
    int main(void)
    {
      int tiles; /* tile size in inches */
    
      
    printf("Enter the size of the tiles in inches > ");
    scanf("%d", &tiles);
    
      char cont = 'Y'; 
       
      while (cont == 'Y' || cont == 'y') {
      int wid_inch;
      int wid_feet;
      int length_inch;
      int length_feet;
      int total_tiles;
      
      double length_total;
      double width_total;
      double length_tile;
      double room_tile;
      
        printf("Enter the room width (feet and inches seperated by a space): ");
        scanf("%d %d", &wid_feet, &wid_inch);
        printf("Enter the room length (feet and inches separated by a space): ");
        scanf("%d %d", &length_feet, &length_inch);
        
        width_total = (wid_feet * 12) + wid_inch;
        room_tile = width_total / tiles;
        length_total = (length_feet * 12) + length_inch;
        length_tile = length_total / tiles;
        total_tiles = room_tile * length_tile;
        printf("The %d'%d width and %d' %d length room requires %d, %d inch tiles\n\n",
                wid_feet, wid_inch, length_feet, length_inch, total_tiles, tiles);
        cont = 'a';
       }
       
    return(0);   
    }
    I need to do a ceil for room_tile and length_tile but whenever I try to do it in anyways that seems logical the compiler goes crazy. How can I do it?

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Like this?
    Code:
          room_tile = ceil(width_total / tiles);
          /* ... */
          length_tile = ceil(length_total / tiles);
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    Posts
    555
    You realize you have to change "cont" in order to stop the loop, or break; out of it. Correct?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by nonpuz
    You realize you have to change "cont" in order to stop the loop, or break; out of it. Correct?
    Code:
     cont = 'a';
       }
    They did. They just never prompt for it, so there's no point in the loop at all.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Sr. Software Engineer filker0's Avatar
    Join Date
    Sep 2005
    Location
    West Virginia
    Posts
    235
    How are you using ceil()?

    Code:
    #include <stdlib.h>
    #include <math.h>
    
    int main(void)
    {
        double x, y, d;
        printf("Enter a value for X and Y, separated by a space: ");
        scanf("%lf %lf", &x, &y);
        if (y != 0)
        {
            d = x / y;
            printf("%lf / %lf = %lf (which rounds to %lf)\n", x, y, d, ceil(d));
        }
        else
        {
            printf("%lf / %lf is undefined (divide by zero)\n", x, y);
        }
        return 0;
    }
    should work just fine. You do have to link with libm, however, which means using a command line that looks like:
    Code:
    cc -lm -o progexe progfile.c
    I hope this helps.

  6. #6
    bignood
    Join Date
    Sep 2005
    Posts
    33
    Whenever I do
    Code:
          room_tile = ceil(width_total / tiles);
          /* ... */
          length_tile = ceil(length_total / tiles);
    I get the following error



    Undefined first referenced
    symbol in file
    ceil /var/tmp//ccF2dmzA.o
    ld: fatal: Symbol referencing errors. No output written to a.out
    collect2: ld returned 1 exit status

  7. #7
    Sr. Software Engineer filker0's Avatar
    Join Date
    Sep 2005
    Location
    West Virginia
    Posts
    235

    libm.a / libm.so

    Quote Originally Posted by 1rwhites
    Whenever I do
    Undefined first referenced
    symbol in file
    ceil /var/tmp//ccF2dmzA.o
    ld: fatal: Symbol referencing errors. No output written to a.out
    collect2: ld returned 1 exit status
    This is because you're not putting the "-lm" (which links against the math library, libm) on the cc command line. The error is a linker error, not a compiler error.

    Read my reply, above, again.

  8. #8
    bignood
    Join Date
    Sep 2005
    Posts
    33
    Dear filker0,
    If you were anywhere near me I would kiss you!

    Thanks a lot. It works fine.

  9. #9
    Sr. Software Engineer filker0's Avatar
    Join Date
    Sep 2005
    Location
    West Virginia
    Posts
    235

    Glad to be of assistance.


    You're quite welcome.

    I always try to be helpful unless I think it's someone trying to get their homework done by someone else, and even then, I'll give hints.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM