I have a program that takes an array of integers, adds the even values and prints the sum. I have a loop that scans in the values for each integer in the array separately, and if the integer is even, it's added to the sum.
The program works, but I want to make sure the values scanned are INTEGERS, not doubles or characters... (this is my first array program, I'm new to programming)
This is the idea that I have:
Code:
if (scanf ("%d", &array[i]))
{
/* do stuff here */
if (array[i] % 2 == 0)
sum = sum + array[i];
}
else
printf ("Please enter an INTEGER.\n");
I think this makes sure that the scanned value is either an integer or a double, and I can clear the buffer with rewind (stdin);
If you can please help me figure out how make sure the value is an INT and not a DOUBLE, I'd be forever thankful Thanks peoplez