1. ## Newbie student

Hi guys,
I am working on a program that will convert the Fahrenheit value taken and returning a celsius.

We have to use a user defined function to calculate. The program doesn't work ofcourse.

Code:
```#include <stdio.h>

float Fahrenheit_to_Celsius();

void main()

{
float fahren;
printf ("Please enter a Fahrenheit value:");
scanf ("%.1f", &fahren);

Fahrenheit_to_Celsius();
{
float celsius, fahren;
celsius=5*(fahren-32.0)/9;
return celsius;
}

printf("%.1f degrees Fahrenheit is %.1f degrees Celsius", fahren, celsius);

}```

I have a question too. I have seen my teacher writing the user defined fuction like this:

Code:
`void calculate(int dice1, int dice2);`
so did he just declared the variables in the fuction?. So will this be a local variable or a global variable?. Sorry I am little confused with fuctions again .

thanks for any help

2. First of all, if you call a function with float as returned value, you need to have a variable to assign that value to. e.g.
Code:
```float var1;

var1 = function(var2, var3);```

3. void calculate(int dice1, int dice2);
This is a function defininition this declares what parameters the function will take

4. Originally Posted by kocika73
First of all, if you call a function with float as returned value, you need to have a variable to assign that value to. e.g.
Code:
```float var1;

var1 = function(var2, var3);```
so is that only for float or int and double too?

5. That is for whatever type the function returns.

aka

int myFunc() ; //returns an int
float myFuct(); //returns a float
char myFunction(); //returns a char

6. Every function has either return value of float, double, int, etc, or it might be void. Void means no return value. If there is no return value, you can call the function in main() by simply writing the name of function and specifying its parameters (if there are any in function definition). If a function however has return value of any kind, you need a variable to assign the return value to. Basically, that's the rule. Otherwise, where would the thing you calculated in the function go to?

7. hmmm, ok thanks guys. I think I will go read more about fuction, didn't quite get it. Thanks for all your help

8. If a function however has return value of any kind, you need a variable to assign the return value to.
Well, to be nitpicky you don't need to capture the return value of a function. You can just ignore it.

9. oh okay, I think now I understand. So the returned value has to be assigned to a variable. So my function return a value that is in "celsius" and that goes back to the main fucntion?.

10. yes. post your updated code.

11. I hope this makes things a little easier for you:
Code:
```#include <stdio.h>

// f = Fahrenheit
// c = Celsius
float f;
float c;

// This function converts fahrenheit to celsius
void Fahrenheit_to_Celsius( void )
{
// Change fahrenheight to celsius

c = 5 * ( f - 32.0 ) / 9;
}

// Starting point of the program, always returns an integer
int main(
void )   // The function main receives no input
{
// Ask the user for a fahrenheit value

printf( "Please enter a Fahrenheit value:" );

scanf( "%f", &f );

// Convert the fahrenheit from user input into celsius

Fahrenheit_to_Celsius( );

// Output to the user our degree conversion

printf( "%.1f degrees Fahrenheit is %.1f degrees Celsius", f, c );

// Return program successfully

return 0;
}```

12. Kleid-0 - global variables for no reason == WRONG !!!!

but at least you didn't use a goto

13. I was so close to using goto, I was like "uuhh I don't know, I've gotta do something wrong with this example...oh I know! Global variables!" lol

14. thanks kleid, that does makes it a lot easier hehe. Yea and teacher says using global variable is a bad habit . I don't know if that's true. Thanks kleid again, now I will go throught the code and learn how you did it.

thanks

15. Another one gone to the darkside. How many is that for you now Kleid-0?