Thread: Problem with area of circle program

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    4

    Problem with area of circle program

    Hi

    The program itself is running fine at first, but for some reason when I enter the radius for multiplication, I keep getting the Area result as 0.
    Any help would be much appreciated!

    Code:
    #include <stdio.h>
    #include <conio.h>
    
    #define PI 3.141569
    
    
    float process(float radius);
    
    int main()
    {
    float area, radius;
    int count;
    
    printf("To STOP, enter 0 for the radius\n"); printf("Radius = ? ");
    scanf("%f", &radius);
    
    for (count = 1; radius !=0; ++count) {
    
    if (radius < 0)
    area = 0;
    else
    area = process(radius);
    
    printf("Area = %f\n", area);
    
    printf("\nRadius = ? ");
    scanf("%f", &radius);
    }
    }
    
    float process(float radius)
    {
    float a;
    a = PI * r * r;
    getch();
    return 0;
    }
    
    

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Code:
    float process(float radius)
    {
    float a;
    a = PI * r * r;
    getch();
    return 0;
    }
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    Jan 2013
    Posts
    4
    My friend the errors are in the function process... you've passed by copy the fload radius but in the function you use a variable r that isn't declared (first error) so you have to replace the R with the RADIUS passed in the function :-) and the second error is that into the function you've returned 0, logically anything that u have typed in the main would be 0!!! you have to return the variable 'a' and you have to calculate as 'a = PI * radius * radius; like following:

    Code:
    float process(float radius){
    float a;
    a = PI * radius * radius;
    return a;
    }
    so also the getch is unuseful... and also the library conio.h is unuseful for this type of program

  4. #4
    Registered User
    Join Date
    Jan 2013
    Posts
    4
    Edited the code as suggested and I've got the following errors. Any suggestions?
    error LNK2005: _main already defined in n.obj

    error LNK2005: "float __cdecl process(float)" (?process@@YAMM@Z) already defined in n.obj
    fatal error LNK1169: one or more multiply defined symbols found

  5. #5
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    Posts
    555
    Your linker is telling you that it already has a definition for a function called 'process' that returns a float and operates on a float. Meaning the file n.obj has a function defined:
    Code:
    float process(float somevar)
    {
    ...
    }
    And you are including that object file in your compilation of THIS code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Area of a circle error, help
    By spazx in forum C Programming
    Replies: 16
    Last Post: 09-14-2010, 06:25 PM
  2. finding area of unit circle by monte carlo..
    By niceguy in forum C Programming
    Replies: 4
    Last Post: 02-25-2008, 01:32 PM
  3. area of a circle
    By wise_ron in forum C Programming
    Replies: 2
    Last Post: 10-02-2006, 03:15 PM
  4. Circle Area
    By Zophixan in forum C++ Programming
    Replies: 3
    Last Post: 11-05-2002, 12:50 PM
  5. Whats wrong with my find Circle Area program?[compiles fine]
    By Golden Bunny in forum C++ Programming
    Replies: 22
    Last Post: 06-16-2002, 02:49 PM