Thread: Problem with more than 1 C function in code

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    2

    Problem with more than 1 C function in code

    I am learning C and having problems with a basic c programming question, below is a simple code with 2 functions, one to calculate area, the other to calculate the perimeter of a circle. The code works if only one function is present, what is wrong?

    Code:
    #include<stdio.h>
    
    
    float ar(int);                     /*function to calculate area*/
    float peri(int);                  /*function to calculate perimeter*/
    
    
    void main()
    {
    int radius;
    
    float area, perimeter;
    
    printf("Enter radius :  ");
    scanf("%d",&radius);
    printf("\n");
    
    area = ar(radius);
    perimeter = peri(radius);
    
    printf("Area is %f\n",area);
    printf("Perimeter is %f\n",perimeter);
    getch();
    }
    
    float ar(int r)
    { float a = 0.0;
      a = 3.14*3.14*r;
      return (a);
    }
    
    float peri(int rad)
    ( float p;
        p = 2.0 * 3.14 * rad;
        return p;
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by tuxson View Post
    Code:
    float peri(int rad)
    ( float p;
        p = 2.0 * 3.14 * rad;
        return p;
    }
    Not all punctuation is created equal. (See red above.)

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    2
    Hey,

    Thanks.. that did it... stupid mistake as usual

  4. #4
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    431
    You might want to try and IDE or editor with brace matching.

    Code:
    /*void main()*/ int main (void)
    Last edited by NeonBlack; 07-22-2008 at 08:17 PM.
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM
  3. using a driver function to test my code??
    By tommy69 in forum C Programming
    Replies: 24
    Last Post: 03-20-2004, 07:12 PM
  4. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM
  5. Big Code, Little Problem
    By CodeMonkey in forum Windows Programming
    Replies: 4
    Last Post: 10-03-2001, 05:14 PM