1. ## functions return value

hi here is my code
Code:
```#include<stdio.h>

int calc(int a, int b);

int main ()
{
printf("pick two numbers: \n");
scanf("%d", &first);
scanf("%d", &second);
if (calc(first, second) == 1)
return 1;
else
return 0;
}

int calc(int a, int b)
{
if (b == 0)
{
printf("you cannot divide with zero");
return 1;
}
else
return (a/b);
}```
when i type in i.e. 10 and 10 theres no output like
"the result is blabla". why that ?
and when i try to divide with zero the message
"you cannot divide with zero" is displayed twice. i dont really know whats wrong with my code.

i hope that someone can help me

2. You call the function twice, that's what causes your problems. It's better not to combine the error and good return values, do something like this.
Code:
```#include<stdio.h>

int calc(int a, int b);

int main ()
{
printf("pick two numbers: \n");
scanf("%d %d", &first, &second);
return 1;
else
return 0;
}

int calc(int a, int b, int *c)
{
if (b == 0)
{
printf("you cannot divide with zero");
return 1;
}
*c = a/b;

return 0;
}```

3. A few things:

Division doesn't always result in an integer -- you might want to use floats or cast to a float and return a float as an answer, otherwise all of your division will result in whole numbers.

The reason you get the double output is because you did this:

if (calc(first, second) == 1)

You called the calc function twice -- once prior to the if statement and once in the condition.

The other problem is the fact that you return 1 if the user tries to divide by 0. See the problem? What's 10 divided by 10? What's 4 divided by 4? What's any number divided by a number of the same value? See my point. You can't use 1 as an error value because division can result in 1 is many situations. You should either pass the address of a bool value (or return a bool value and pass the address of a float to store the answer) to store whether or not the operation was successful (IE no division by 0), or throw an exception.

On a side note -- it's not always a good idea to display error information from within the function. You're best off allowing that to be dealt with on a case by case basis.

4. with that:
Code:
```if (b == 0)
{
printf("you cannot divide with zero");
return 1;
}```
i wanted to exit the function with return 1, what
means that there was an error during the function.
i thought 0 is going to tell the program that it can exit
and with 1 it can exit but knows that there was an error.
with
Code:
```if (calc(first, second) == 1)
return 1;```
i wanted to check if the function calc exited normal or
with an error value like 1.
if so, main should exit with returning 1 to itself.

thanks