I have to write a function to find the circumference of a circle. I am having problems cause I dont have any idea how to do that. I know ya'll like to have some kind of showing of my own program the only thing is that I dont understand what to do or where to start. My teacher is no help. I dont like the way he teaches. Maybe someone here can get me to understand a function with an example or something.

My program started

``````#include<iostream.h>
void my_sum(int r)
{
float sum;
sum = 2*3.14*r;
cout<<"The circumference of a circle is "<<sum<<"."<<endl;
}
int main()
{
``````

Im stuck. I dont think this is even right. I dont know what I am doing. Please someone help.

Kelly

Edited by pyTony: fixed formating

7
Contributors
6
Replies
7
Views
13 Years
Discussion Span
Last Post by frrossk

Try compiling and running the code you are developing.

``````#include<iostream>
using namespace std;

void my_sum(int r)
{
float sum;
sum = 2 * 3.14 * r;
cout << "The circumference of a circle is " << sum << "." << endl;
}

int main()
{
my_sum(1);
return 0;
}``````

Maybe someone here can get me to understand a function with an example or something.

your function looks correct...although you should probably change that "int r" to a float.

are you having trouble understanding the concept of functions?

if thats the case then a quick example would be something like this

``````int addone(int x)
{
return x+1;
}

int main()
{
int z = 5;
}``````

the end value of z here would be 7.
hope it helped...

Hello, sorry, be right back!

#include<iostream.h>
float my_sum(int r);
void main()
{
int r;
cin>>r;
my_sum(r);
}

float my_sum(int r)

{
float sum;
sum = 2*3.14*r;
cout<<"The circumference of a circle is "<<sum<<"."<<endl;
}

this will work.
please let me know if it is fine or not.

It looks like you missed the Dave's post...
Why did you switch to void main() ?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.