If we analyze this function:
int isdigit()
{
int x, y;
printf("inserte dos numeros\n");
scanf_s("%d""%d",&x,&y);
return x;
return y;
}
We see that you have the following errors:
Possible solutions:
Simple reading
You have a function that returns an integer. To read two values you will have to call the function twice:
int readInt()
{
int x;
while( !scanf("%d",&x) )
{
while ((c = getchar()) != '\n' && c != EOF); // limpieza del buffer de entrada
printf("ERROR: No era un numero. Intentalo de nuevo: ");
}
return x;
}
int main()
{
puts("Introduzca dos números: ");
int x = readInt();
int y = readInt();
int z = x + y;
printf("%d\n",z);
}
Example in ideone
Double reading with pointers
In this case the function reads the two numbers and returns them. To return the values use pointers received as arguments
void readInts(int* a, int* b)
{
int x;
while( scanf("%d %d",a,b) != 2 )
{
char c;
while ((c = getchar()) != '\n' && c != EOF); // limpieza del buffer de entrada
printf("ERROR: Uno de los valores no era un número. Intentalo de nuevo: ");
}
return x;
}
int main()
{
puts("Introduzca dos números: ");
int x, y;
readInts(&x,&y);
int z = x + y;
printf("Resultado: %d\n",z);
}
Example in ideone
Composite reading with return
As I mentioned, in C the returned values have to be packed in a single return
. This does not mean that only an integer can be returned ... structures can also be returned with all the information we need:
typedef struct
{
int x;
int y;
} TwoInts;
TwoInts readInts()
{
TwoInts toReturn;
while( scanf("%d %d",&toReturn.x,&toReturn.y) != 2 )
{
char c;
while ((c = getchar()) != '\n' && c != EOF); // limpieza del buffer de entrada
printf("ERROR: Uno de los valores no era un número. Intentalo de nuevo: ");
}
return toReturn;;
}
int main()
{
puts("Introduzca dos números: ");
TwoInts twoInts = readInts();
int z = twoInts.x + twoInts.y;
printf("Resultado: %d\n",z);
}
Example in ideone