Hey there,

I am working on my first solo program and running into a road block. I keep going back to various sources for function syntax, and it seems like I am writing correctly. Probably not. I am hoping that some new eyes can point out my screw-ups below. Note: my compiler (using the Pelles C IDE).

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

int choice;
float temp;                   /* this is the user imput and thus the variable for the converter function */

float convertF(void);
float convertC(void);   /* prototyped the converter functions */

int main()
{
for( ; ; )
{
printf( "Enter a number to make a selection:\n" );
printf( "\n 1. Farenheit to Celsius\n 2. Celsius to Farenheit\n 3. Quit\n" );
scanf( "%d", &choice);

if(choice==1)
{
float result;

printf( "Please enter a decimal Farenheit value (e.g. 32.0)\n" );
scanf( "%f", temp );

result=convertF(void);

printf( "\n %f degrees Farenheit equals %f degrees Celsius \n", temp, result);

continue;
}

if(choice==2)
{
printf( "Please enter a decimal Celsius value (e.g. 10.5)\n");
continue;
}

if(choice==3)
{
printf( "Goodbye!\n");
break;
}
}

return(0);
}

float convertF(void)
{
float Cel;

Cel=(temp - 32)/1.8;
return(Cel);
}

float convertC(void)
{
float Far;

Far=(temp * 1.8) + 32;
return(Far);
}```
I am getting 2 main errors:

(1) the "result=convertF(void);" is getting an "illegal expression" error. Note that the convertF function was originally convertF(temp); my thinking being that I wanted to pass the temp value obtained from the user to the function. I got a lot more errors with that set-up, so I changed it to void as an experiment (and got less errors). Hmm...

(2) the same expression from (1) is also getting a "too many arguments for convertF" error. I just don't get this one, because at least one reference uses this format in an example of a function call.

Anyway, please tell me what I am doing wrong with the functions/function calls.

2. So, you can't pass "void" to a function. If you don't want to pass anything to a function, then, don't pass anything to the function.

Your original thought was correct, you do indeed need to pass things to the function. Comments:
Code:
```#include <stdio.h>

int choice;  /*bad and wrong */
float temp; /*bad and wrong */

float convertF(void);  /*incorrect prototype for this function */
float convertC(void);   /*incorrect prototype for this function */

int main()
{
for( ; ; )  /* possibly the worst way to do this loop */
{
printf( "Enter a number to make a selection:\n" );
printf( "\n 1. Farenheit to Celsius\n 2. Celsius to Farenheit\n 3. Quit\n" );
scanf( "%d", &choice);

if(choice==1)
{
float result;

printf( "Please enter a decimal Farenheit value (e.g. 32.0)\n" );
scanf( "%f", temp );

result=convertF(void);  /*you need to tell convertF about the input*/

printf( "\n %f degrees Farenheit equals %f degrees Celsius \n", temp, result);

continue;  /* pointless */
}

if(choice==2)
{
printf( "Please enter a decimal Celsius value (e.g. 10.5)\n");
continue;  /* similarly pointless */
}

if(choice==3)
{
printf( "Goodbye!\n");
break;
}
}

return(0);
}

float convertF(void)  /*convertF must take an input parameter, presumably of type float, if you want to be able to use "temp" below */
{
float Cel;

Cel=(temp - 32)/1.8;
return(Cel);
}

float convertC(void)   /*convertC must take an input parameter, presumably of type float, if you want to be able to use "temp" below */
{
float Far;

Far=(temp * 1.8) + 32;
return(Far);
}```

First, thanks for your thoughts. I have a couple follow up questions, if you don't mind.

Was my original "float convertF(temp)" the correct way to pass temp to the function? If so, what is with the errors I mentioned?

Also, what is the correct way to make to program run until the user "quits?" That was my intention with the infinite loop.

Finally, why were my global variable declarations "bad and wrong?"

4. To take the questions in reverse order, 999999 times of 1000000 global variables are bad and wrong. In this case, they were a hack to prevent you from having to learn about functions. As it was, you were only able to convert one thing to fahrenheit. Should you, at some point, need to convert two different things to fahrenheit, then you would have to write another function, with a slightly different name, using a different global variable. And then, should you need to convert three different things .....

The cheap and easy way to run until the program quits is to loop until choice equals 3. That's what choice is supposed to do, after all.

So convertF(temp) is the correct way to pass temp to the function -- note the lack of the word float there, just as you don't have float in your code now either. That means you would need to define the function to take a parameter -- and when defining the function, you need to specify the type of the parameter as well, so the definition would contain (float temp).

5. Firstly, a quote
Originally Posted by Wikipedia
They are usually considered bad practice precisely because of their nonlocality: a global variable can potentially be modified from anywhere, (unless they reside in protected memory) and any part of the program may depend on it. A global variable therefore has an unlimited potential for creating mutual dependencies, and adding mutual dependencies increases complexity. See Action at a distance. However, in a few cases, global variables can be suitable for use. For example, they can be used to avoid having to pass frequently-used variables continuously throughout several functions.