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

This is a discussion on HELP with Total number of even and odd numbers (not sum) within the C++ Programming forums, part of the General Programming Boards category; This is my HW question: Write a program that will ask the user to input 10 non-negative numbers. Your program ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    1

    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 ...help please?

    Code:
    #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;
      
     sum=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>>even<<endl;
          else
               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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,528
    You're approacing this in the wrong way..(aside from syntax problems).
    Code:
    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.
    Manasij Mukherjee | gcc-4.9.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,021
    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, 05:04 PM
  2. C Program that counts total prime number?
    By exe101 in forum C Programming
    Replies: 2
    Last Post: 04-07-2009, 02: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21