Code:
double function(void)
int main(void)
{
double var = function();
printf("%lf\n",var);
//or
printf("%lf\n", function() );
return 0;
}
double function(void)
{
code
return answer;
}
or put the entire function above main, then main.
Code:
double function(void)
{
code
return answer;
}
int main (void)
{
double var = function();
printf("%lf\n", var);
//or
double var;
var = function();
printf("%lf\n",var);
//or
printf("%lf\n", function() );
return 0;
}
but, you have your printf in your function already soo...that kind of defeats the point of a return value. Unless you're just checking it prior to getting that return value.
as far as proper etiquette, the function would just do the math and return the value then the user would do his or hers printf on the textual formatting with the return value.
Code:
double function(int rad)
{
return (rad*rad*Pi);
}
just so you can see the different methods of doing this.
Code:
#include <stdio.h>
double function( int rad)
{
#define Pi 3.14
return (rad*rad*Pi);
}
int main(void)
{
int rady;
printf("give me something\n");
scanf("%d", &rady);
printf("whatever you want to say here: = %lf \n",function(rady) );
return 0;
}
P.S. you do not need the math header either, because you are doing the math in your function. Not using a function included in the math header .
mod: I just read the comments in your code: Hint:
to get two variables off the cli one after the other just print out what you want then scanf twice, one after the other in logical order to grab the two of them, then process them accordingly.
these are touching, they need spaces
Code:
#include<stdio.h>
#include<math.h>
#definePi 3.14
//like this
#include <stdio.h>
#include <math.h>
#define Pi 3.14