# Thread: Even / Odd Counting with Loops

1. ## Even / Odd Counting with Loops

I can easily figure out how to determine how whether or not a number is even/odd and display that using if-else statements. No problem!

But as I attempt to complete the same task using a sentinal loop; let alone count them up in and print out a message stating how many of each were entered; I am screwed! I was wondering if anyone could provide some pointers in the right direction. This is what I have now:

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

int main()
{
int num;
int oddcount, int evencount;

printf("\nThis program will ask you to enter numbers and determine whether they are even or odd. It will also count how many of each you entered.");

oddcount=0;
evencount=0;

while (num!=999)
{
printf("Enter a number: (to stop entering numbers enter 999) ");
scanf("%d",&num);

if (num%2 != 0)

printf("\nThe number %d Is Odd.\n",num);
oddcount++;

else if (num%2 == 0)

printf("\nThe number %d Is Even.\n",num);
evencount++;

return 0;
}```

2. You are missing a few braces. And notice how more careful indenting makes it easier to read.
Code:
```#include< stdio.h>

int main()
{
int num;
int oddcount, evencount;

printf("This program will ask you to enter numbers and determine"
" whether they are even or odd. It will also count how many"
" of each you entered.\n");

oddcount = 0;
evencount = 0;

while (num != 999)
{
printf("Enter a number: (to stop entering numbers enter 999) ");
scanf("%d", &num);

if (num%2 != 0)
{
printf("\nThe number %d Is Odd.\n", num);
oddcount++;
}
else
{
printf("\nThe number %d Is Even.\n", num);
evencount++;
}
}
return 0;
}```

3. ## One last thing?

I appreciate the help, those braces are killing me! The only thing is that I can't get it to complile. I was using my flowchart to create the counting statments requried at the end, and I am getting like 10 compiler errors. Does anyone know how to help me this one time? Please!

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

int main()
{
int num;
int oddcount;
int evencount;

printf("\nThis program will ask you to enter numbers and determine  whether they are even or odd. It will also count how many of each you entered.\n");

oddcount=0;
evencount=0;

while (num!=999)
{
printf("Enter a number: (to stop entering numbers enter 999) ");
scanf("%d",&num);

if (num%2 != 0)
{
printf("\nThe number %d Is Odd.\n",num);
oddcount++;
}
else
{
printf("\nThe number %d Is Even.\n",num);
evencount++;
}
}
printf("\nThe number of odd numbers entered was %d, oddcount);
printf("\nThe number of even numbers entered was %d, evencount);

return 0;
}```

4. Hi, I think you forgot to put " in your last printf statements

Code:
```printf("\nThe number of odd numbers entered was &#37;d",oddcount);
printf("\nThe number of even numbers entered was %d" , evencount);```

5. Not only that, you've put a space before stdio.h.

Code:
`#include< stdio.h>`
try
Code:
`#include <stdio.h>`
That should remove all errors except the printf() ones, which nynicue has already explained.

6. ## Stupid Compiler

Thanks for the feedback, stupid errors! It was so early in the morning. I am trying to compile and everything is good. But when I execute it, this is what I get:

C:\Documents and Settings\Christopher\Desktop\C Programming\Midterm\Midterm two.c(12): error #2092: Missing identifier.
C:\Documents and Settings\Christopher\Desktop\C Programming\Midterm\Midterm two.c(12): error #2001: Syntax error: expected ';' but found 'int'.
C:\Documents and Settings\Christopher\Desktop\C Programming\Midterm\Midterm two.c(29): error #2157: Unrecognized statement.
C:\Documents and Settings\Christopher\Desktop\C Programming\Midterm\Midterm two.c(29): error #2001: Syntax error: expected ';' but found 'if'.
C:\Documents and Settings\Christopher\Desktop\C Programming\Midterm\Midterm two.c(35): warning #2096: Missing return value.
C:\Documents and Settings\Christopher\Desktop\C Programming\Midterm\Midterm two.c(35): error #2001: Syntax error: expected '}' but found 'end of input'.
*** Error code: 1 ***

This is screwing me big time, so much for the career as a programmer! Help once again please!

7. If this is what you get, you didn't compile correctly. You're missing braces again.

8. ## Thanks

Thank you for all the help! I had another file in my compiler that I needed to exclude. You guys really know your stuff!