Stuck writing a Function

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2004
Posts: 6
Reputation: kellyandtopher is an unknown quantity at this point 
Solved Threads: 0
kellyandtopher kellyandtopher is offline Offline
Newbie Poster

Stuck writing a Function

 
0
  #1
Jan 3rd, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,451
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 250
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Stuck writing a Function

 
0
  #2
Jan 3rd, 2005
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;
}
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 13
Reputation: kaiser<lucy> is an unknown quantity at this point 
Solved Threads: 1
kaiser<lucy> kaiser<lucy> is offline Offline
Newbie Poster

Re: Stuck writing a Function

 
0
  #3
Jan 3rd, 2005
Originally Posted by kellyandtopher
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
  1. int addone(int x)
  2. {
  3. return x+1;
  4. }
  5.  
  6. int main()
  7. {
  8. int z = 5;
  9. z = addone(z);
  10. z = addone(z);
  11. }
the end value of z here would be 7.
hope it helped...
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 4
Reputation: Sadako is an unknown quantity at this point 
Solved Threads: 0
Sadako's Avatar
Sadako Sadako is offline Offline
Newbie Poster

Re: Stuck writing a Function

 
0
  #4
Jan 3rd, 2005
Hello, sorry, be right back!
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 14
Reputation: Tresa is an unknown quantity at this point 
Solved Threads: 0
Tresa Tresa is offline Offline
Newbie Poster

Re: Stuck writing a Function

 
0
  #5
Jan 5th, 2005
#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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 108
Reputation: prog-bman is an unknown quantity at this point 
Solved Threads: 3
prog-bman prog-bman is offline Offline
Junior Poster

Re: Stuck writing a Function

 
0
  #6
Jan 5th, 2005
Join me on IRC:
Server: irc.daniweb.com
Channel: #C++

Chat Via:
http://daniweb.com/chat/minichat.php
or
Your favorite IRC client.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 220
Reputation: frrossk is an unknown quantity at this point 
Solved Threads: 9
frrossk's Avatar
frrossk frrossk is offline Offline
Posting Whiz in Training

Re: Stuck writing a Function

 
0
  #7
Jan 5th, 2005
It looks like you missed the Dave's post...
Why did you switch to void main() ?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC