Thread: basic question of using function in C++

  1. #1
    Registered User
    Join Date
    Dec 2016
    Posts
    2

    basic question of using function in C++

    Hi,

    i have a question of how using function in writing a program of C++.

    the question is

    "Write a function, sVolume, which takes a radius as an integer, r and returns the value of the sphere volume, based on the equation: sVolume=4/3*3.14*3.14*3.14*3.14 where r=3.14 "

    hope u to answer my question asap.
    best regards.

  2. #2
    Old Took
    Join Date
    Nov 2016
    Location
    Londonistan
    Posts
    121
    Well I for one am not going to do your rather simple homework for you.

    Post your attempt at solving the problem and I'll help you fix it should it be needed.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Hint: The correct equation is Volume = 4/3 * Pi * r * r * r

    Tim S.
    "...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

  4. #4
    Registered User
    Join Date
    Dec 2016
    Posts
    2
    Quote Originally Posted by Hobbit View Post
    Well I for one am not going to do your rather simple homework for you.

    Post your attempt at solving the problem and I'll help you fix it should it be needed.
    my attempt is

    #include <iostream>
    using namespace std;

    float sVolume(float v);

    float r=3.14;
    float v= 4/3*3.14*r*r*r;
    return v;

  5. #5
    Old Took
    Join Date
    Nov 2016
    Location
    Londonistan
    Posts
    121
    You'll get there. firstly functions need braces....
    Code:
    return_type name( arguments )
    {
       // code goes here
    }
    Next think about what you need to pass as an argument to the function... the radius, which your exercise says should be int, but you show as a floating point number. Do the calculation then return the result.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-23-2011, 09:00 AM
  2. Basic pointer in function question
    By Origin in forum C Programming
    Replies: 15
    Last Post: 04-01-2010, 10:14 AM
  3. Function name basic question help
    By kenryuakuma in forum C++ Programming
    Replies: 7
    Last Post: 09-24-2008, 07:48 AM
  4. Replies: 9
    Last Post: 06-09-2008, 09:53 AM
  5. basic recursion function question. typo in book?
    By navyzack in forum C Programming
    Replies: 6
    Last Post: 04-18-2005, 11:07 AM

Tags for this Thread