Thread: Compiling errors

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    3

    Compiling errors

    The following program won't compile correctly. I have the error message being given to me as I try and compile it. Does anyone have a solution? Also, is the last half correct in order to get the box to be drawn with the character selected by the user?

    Program:

    Code:
    #include <stdio.h>
    
    int computeSurfaceArea (int, int, int);
    int computeVolume (int, int, int);
    void displayTopBottom (int, int);
    void displayyFrontBack (int, int);
    void displaySide (int, int);
    
    int main ()
    
    {
       char choices;
       int width;
       int height;
       int depth;
       char symbol,ch1, ch;
       int OK;
    
       do {
          printf("Enter the width -- must be a positive integer: ");
          scanf("%d", &width);
       }
       while (width < 0);
      do
    
    
       do
       {
          printf("Enter the height -- must be a positive integer: ");
          scanf("%d", &height);
       }
       while (height < 0);
    
    
       do
       {
          printf("Enter the depth -- must be a positive integer: ");
          scanf("%d", &depth);
       }
       while (depth < 0);
    
    
    
          printf("Enter a character to be used to draw: ");
          scanf("%s", &symbol);
    
    
      do
      {
       printf("Menu\n");
       printf("A -- Calculate the Surface Area of the Box\n");
       printf("V -- Calculate the Volume of the Box\n");
       printf("F -- Display the Front/Back of the Box\n");
       printf("T -- Display the Top/Bottom of the Box\n");
       printf("S -- Display the Side of the Box\n");
       printf("Q -- Quit\n");
    
       printf("Please make a selection\n");
       scanf("%d",&ch);
       ch1 = getchar();
    
       OK = 0;
    
       switch (ch)
       {
          case 'A':
      Volume (height, width, depth);
      OK = 1;
      break;
    
          case 'F':
            FrontBack (width, height);
      OK = 1;
      break;
    
          case 'T':
            TopBottom (width, depth);
      OK = 1;
      break;
    
          case 'S':
           Side (depth, height);
      OK =1;
      break;
    
          case 'Q':
      OK = 1;
      break;
    
     default:
      printf("Please make another selection\n");
      OK = 0;
    }
      }
      while (OK = 0);
    
    
      return 0;
    }
    
      int computeSurfaceArea  (int width, int depth, int height)
     {
         int area = (2 * width * depth) + (2 * height * width) + (2 * depth * height);
         return area;
      }
    
      int computeVolume  (int width, int depth, int height)
      {
         int volume = (depth * width * height);
         return volume;
      }
    
      void displayFrontBack(int a        , int b         )
    {
       int i,j;
       for(j=0; j < b-1;j++)
       {for(i=0;i< a-1;i++)
          printf("%c",'*');
             printf("\n");
       }
    }
    
      void  displayTopBottom(int b        , int c        )
    {
       int i,j;
       for(j=0; j<b-1; j++)
       {for(i=0; i< c-1; i++)
          printf("%c", '*');
       printf("\n");
       }
    }
    
      void  displaySide(int a       , int c       )
    {
       int i,j;
       for(j=0; j<c-1; j++)
       {for(i=0; i<a-1; i++)
          printf("%c", '*');
       printf("\n");
     }
    }
    Error message:

    /tmp/ccM2czSC.o: In function `main':
    /tmp/ccM2czSC.o(.text+0x157): undefined reference to `SurfaceArea'
    /tmp/ccM2czSC.o(.text+0x17c): undefined reference to `Volume'
    /tmp/ccM2czSC.o(.text+0x197): undefined reference to `FrontBack'
    /tmp/ccM2czSC.o(.text+0x1b2): undefined reference to `TopBottom'
    /tmp/ccM2czSC.o(.text+0x1cd): undefined reference to `Side'
    collect2: ld returned 1 exit status

    Thanks!

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    More or less just what the errors say. You define a function, for example, called
    Code:
    int computeVolume (int, int, int);
    But you try to call a function like this.
    Code:
    Volume (height, width, depth);
    Notice that computeVolume is not that same as Volume.

    Also, you've got a misplaced do.
    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
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Write 5 lines and compile is a debug strategy.
    Write 100 lines and dump on a message board for someone else to fix isn't.

    Basically, you write as much as you feel you can cope with if it all goes wrong, and then you have a lot less to look at, and a lot less to fix.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Replies: 4
    Last Post: 03-10-2008, 07:03 AM
  3. Quincy 2005: Compiling Errors
    By Thileepan_Bala in forum C Programming
    Replies: 6
    Last Post: 01-18-2008, 08:26 PM
  4. Replies: 2
    Last Post: 12-07-2004, 02:31 AM
  5. errors in my class....
    By o0obruceleeo0o in forum C++ Programming
    Replies: 9
    Last Post: 04-14-2003, 03:22 AM