Thread: HELP with Total number of even and odd numbers (not sum)

  1. #1
    Registered User
    Join Date
    Nov 2011

    Unhappy HELP with Total number of even and odd numbers (not sum)

    This is my HW question:

    Write a program that will ask the user to input 10 non-negative numbers. Your program should reject the number if it is negative, and make the user type a non-negative number. Your program should then compute and report the following statistics about the numbers entered: sum of the numbers, average of the numbers, # of odd numbers entered, # of even numbers entered.

    I need help getting the total number of odd and even numbers this is what I have please?

    #include< iostream>
     #include <cmath>
     Using namespace std;
     int main ()
     int a,b,c,d,e,f,g,h,i,j;
     int sum,avg,even,odd;
     cout << “Input ten non-negative numbers: ”
     cin >> a >> b >> c >> d >> e >> f >> g >> h >> i >> j;
     avg= sum/10
           if ( a,b,c,d,e,f,g,h,i,j % 2 == 0 )
               cin>> odd<< endl;
                 if (a,b,c,d,e,f,g,h,I,j>=0)
                 cout <<sum<<" " <<avg<< " "<<odd << " "<<even;
                 else (a,b,c,d,e,f,g,h,i,j <0)
                 cout << "You entered a negative number! ";
     return 0;
    I Greatly Appreciate Your Help =]

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    You're approacing this in the wrong way..(aside from syntax problems).
    Run a loop..for ten times.
             Ask the user to input a number.
             If the entered number is -ve, do not increment the counter variable, show an error.
             If it is +ve,
                      add it to the sum..and increment the counter.
                      if it is even, add 1 to the even counter...else add 1 to the odd one.
    Average = Sum / 10
    Display your results.

  3. #3
    Join Date
    Oct 2007
    Inside my computer
    I would have left the variables as an exercise, though... counters and that stuff should easily be realized as long as one simply draws a proper flow chart and think and test it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. read n numbers and find their total, min, max, average
    By jackson6612 in forum C++ Programming
    Replies: 2
    Last Post: 04-23-2011, 04:04 PM
  2. C Program that counts total prime number?
    By exe101 in forum C Programming
    Replies: 2
    Last Post: 04-07-2009, 01:18 AM
  3. Newbie - i need a total of list of numbers
    By sugie in forum C++ Programming
    Replies: 9
    Last Post: 02-25-2005, 03:58 PM
  4. retrieving number of socket being used/open & total bandwidth
    By hanhao in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-08-2004, 10:39 AM
  5. Printing total of 1's in binary number
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 11-18-2001, 02:50 PM