Thread: Odd/Even counter.

  1. #1
    Registered User
    Join Date
    Aug 2010

    Odd/Even counter.

    I have written a program to count the number of even and odd numbers entered from a list; but currently it wont work correctly, think its my modulus operators in the wrong place, but not 100%. Pretty knew to this.

    /* Program to count the no of even and odd numbers*/

    #include <stdio.h>
    void main( )

    int a[100], n, count_odd=0, count_evn=0,I;

    printf("Enter numbers in array");
    printf("Enter the integars, seperated by a space");
    for (I=0;I < n;I++);
    for(I=0;I < n;I++)

    if(a[I] % 2 == 0)

    printf("There are %d negative numbers in the arrayn\n",count_odd);
    printf("There are %d positive numbers in the arrayn",count_evn);

    Any suggestions would be appreciated. Thanks.

  2. #2
    Registered User
    Join Date
    Aug 2003
    Few things first:
    Read the sticky posts, you will learn to use code tags.
    Read the FAQ, void main should only be used in very few very specific cases, use int main.

    As to your code, your problem is probably this line:
    for (I=0;I < n;I++);
    Get rid of that last semi-colon.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    That program will not compile, and that is even excluding the fact that void main should be int main.

    Furthermore, is this supposed to be C or C++?

    Please remember to indent your code properly and post it within [code][/code] bbcode tags.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Aug 2003
    Ah missed that compiler error...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 11-01-2009, 09:54 AM
  2. Promblem with code
    By watchdogger in forum C Programming
    Replies: 18
    Last Post: 01-31-2009, 06:36 PM
  3. Page File counter and Private Bytes Counter
    By George2 in forum Tech Board
    Replies: 0
    Last Post: 01-31-2008, 03:17 AM
  4. Counter Heap Sort
    By Achillles in forum C++ Programming
    Replies: 1
    Last Post: 10-09-2002, 12:17 PM
  5. how to obtain first character of every other word
    By archie in forum C++ Programming
    Replies: 8
    Last Post: 02-18-2002, 01:58 PM