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).
I am getting 2 main errors: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); }
(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.



LinkBack URL
About LinkBacks



