Thread: User Decined Functions

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    1

    User Decined Functions

    I have a project in my C Programing class,but I am having a little trouble.I have to create a user defind function, for finding the volume of a sphere given the radius.

    The function should be called "sphere_volume) and called from the main program.

    When it is called from the main program it will look like this: sphere_volume(r);

    This is what I have so far but I keep getting errors. Any suggestions? THANKS


    Code:
    // Class Redo.cpp : Defines the entry point for the console application.
    
    #include "stdafx.h"
    #include "math.h"
    
    double sphere_volume(double r, int v);
    
    
    int/* _t */ main (void) //(int argc, _TCHAR* argv[])
    {
    double r,
    v;
    
    /* ASK FOR RADIUS */
    
    printf("Enter the radius of the circle:"),
    scanf ("%lf", &r);
    
    /* OUTPUT VOLUME */
    
    printf("The volume is %f \n",sphere_volume (r));
    
    
    return 0;
    }
    
    double sphere_volume ( double r)
    {
    v=4/3*3.14*pow(r,3) ;
    return (v);
    }

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    When you get errors, you should mention what they are instead of simply saying they happened.

    I see one obvious problem: Your prototype for sphere_volume() doesn't match the function definition.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I see another easy error - your program is C++, and you've posted this on the C board.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Style Points
    By jason_m in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 06:15 AM
  2. running shell functions based on user input.
    By System_159 in forum Linux Programming
    Replies: 14
    Last Post: 10-12-2007, 07:19 PM
  3. SSH Hacker Activity!! AAHHH!!
    By Kleid-0 in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 03-06-2005, 03:53 PM
  4. Attaching functions to a class/struct
    By VirtualAce in forum Tech Board
    Replies: 2
    Last Post: 08-04-2003, 10:56 AM
  5. Expression Manipulator v0.2 (bug fixes, functions)
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-26-2003, 04:52 PM