+ 1
Starting to write functions in C [SOLVED]
I am writing a code with four functions (not including the main). As of right now, I only have two and I am trying to get them to work before I move on to the next two within this code. I believe I am having problems with some syntax because my code returns errors and is not functional yet. Can someone tell me where I am going wrong here? (Also yes, I know I do not have a print statement in the main function for the average, only the max number). https://code.sololearn.com/c642VYe5p35f/?ref=app
4 Respuestas
+ 2
The compiler should already inform you that there are unexpected break statements; you don't need break to terminate a function, that is what return does. Also, you are missing a terminating curly brace after the definition of max().
However, your logic to determine the largest of four numbers is incorrect. Consider the input
3 1 2 4
where your conditional would immeditely return 3, although 4 is bigger. You need to compare the first number to the following three and return it only if it is bigger than each of them, otherwise compare the second to the following two and return it if it is bigger, and so on.
+ 1
No need of break statement after returning value.
Return automatically breaks the execution. So remove it.
And one } is missing.
0
To everyone who commented, thank you. I took many of your guys suggestions. Below I have attached my completed code if you would like to take a look at it.
(Input requires 4 integer variables, preferably all different for the sake of the program)
https://code.sololearn.com/clwSiZ27pCcM/?ref=app