954,173 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Stuck writing a Function

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
void my_sum(int r)
{
float sum;
sum = 2*3.14*r;
cout<<"The circumference of a circle is "<

kellyandtopher
Newbie Poster
6 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

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;
}
Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 
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...

kaiser<lucy>
Newbie Poster
13 posts since Nov 2004
Reputation Points: 10
Solved Threads: 1
 

Hello, sorry, be right back!

Sadako
Newbie Poster
4 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

#include
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 "<

Tresa
Newbie Poster
14 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 
prog-bman
Junior Poster
109 posts since Nov 2004
Reputation Points: 14
Solved Threads: 4
 

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

frrossk
Posting Whiz in Training
220 posts since Sep 2004
Reputation Points: 17
Solved Threads: 9
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You