# Thread: some problem with my code

1. ## some problem with my code

Can you please tell me what I did wrong with this code?

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

int min(int x, int y);

int main(){

int x;

int y;

int minimum;

printf("les inn x: ");

scanf("%d" , &x);

printf("les inn y: ");

scanf("%d" , &y);

minimum=min(x, y);

printf("%d er det minste tallet\n" , minimum);

return 0;
}

int min(){

int minimum;
int x;
int y;

if (x<=y){

minimum=x;
}

else if (y<=x){

minimum=y;
}

return minimum;
}```
Im having a real hard time understanding how functions work.

EDIT: I now see what I did wrong. x and y is not declared to any value in the min function. How can I declare it to get the value from main function? I thought it would happen on its own

EDIT: I see my mistake and fixed the problem  2. Your min() function should be:
Code:
```int min(int a, int b)
{
if ( a < b )
return a;
return b;
}``` 3. Theres also an even simpler way:
Code:
`#define min(a,b) ((a < b) ? a : b)` 4. The logic is essentially the same though, so I daresay it isn't simpler, and after all it also comes with pitfalls: the issue of precedence for complex expressions, and the issue of side effects, as rare as they might be in practice. So to address the former:
Code:
`#define min(a,b) (((a) < (b)) ? (a) : (b))` 5. Be careful with the preprocessor - Consider what happens with the following in some sort of loop...
Code:
`min(++i, MAXIMUM_APPLES);` Popular pages Recent additions inn, int, minimum;, printfles, scanf%d 