Hey all, I'm new to these boards even though I've been surfing them for a few months now. I thought this would be a good starting post. Anyway, I'm taking computer intro in college (using C) and I have a problem with a certain program I have to complete. I have to write a program that inputs a series of integers and passes them one at a time to function even which uses the remainder operator to determine if an integer is even. The function should take an integer argument and return 1 if the integer is even and o otherwise. Now, I thought this is how it should look, but I can't get the return to actually return a 1 for even, or 0 for odd.
Code:
#include <stdio.h>
int even(int num);
void main()
{
int num;
printf("Enter a positive integer (-1 to exit): ");
scanf("%d", &num);
even(num);
while (num != -1)
{
printf("Enter a positive integer (-1 to exit): ");
scanf("%d", &num);
even(num);
}
}
int even(int num)
{
if (num % 2 == 0)
return 1;
else
return 0;
}