Thread: display the odd numbers and average the even numbers between two integers

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    2

    display the odd numbers and average the even numbers between two integers

    In C++ I am trying to display the odd numbers and average the even numbers between two integers.

    The following is the code i have thus far...

    This is what I have thus far..but cant figure out how to only display the odd numbers...havent begun averaging the even numbers....:

    #include <iostream>
    using namespace std;

    void main (void)
    {
    int num1, num2, num = 0;

    cout << "Please enter the the two numbers" <<endl;
    cin>> num1 >> num2;


    while (num1++ < num2)

    cout <<num1;

    if(num1 % 2 ==0)
    cout << num1;

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    2
    Originally posted by Hammer
    Read about Code tags
    void main
    odd and even
    After reading the material provided I am still unable to determine how to display odd numbers between two randomly selected integers.

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Originally posted by bmilton
    After reading the material provided I am still unable to determine how to display odd numbers between two randomly selected integers.
    if you read the odd and even page, you should know. just replace the printf with cout.

    you don't really even need a fxn.
    here is your biggest hint. use %.

    edit: you also need to fix your code, and the first two links Hammer posted shall not be taken lightly.

    edit2: you have used %. just think about it. you have:
    Code:
    if(num1 % 2 == 0)
      cout << num1;
    your answer is right there. just think about it. it's not that tough, and the odd and even faq link has the answer.
    Last edited by alpha; 03-03-2003 at 03:31 PM.

  5. #5
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Originally posted by bmilton
    In C++ I am trying to ... average the even numbers between two integers.
    This part is very simple. You don't even have to find the even numbers.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help in finding average of a class of numbers
    By hastefan2001 in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2009, 01:11 PM
  2. Newbie : Getting the average of 3 numbers
    By Swerve in forum C++ Programming
    Replies: 10
    Last Post: 08-27-2007, 05:02 PM
  3. how unlimited the amount of numbers to average
    By Machewy in forum C++ Programming
    Replies: 3
    Last Post: 05-21-2003, 08:44 AM
  4. arrays
    By john_murphy69 in forum C Programming
    Replies: 8
    Last Post: 02-11-2003, 02:33 PM
  5. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM