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

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;
z = addone(z);
z = addone(z);
}

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;
cout<<"Enter the radius";
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() ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.