Can somebody help me please with a sequence odd or even number program?

How do I write a sequence odd or even number program? I need to make one but I'm confused. Can somebody help me please, I would really appreaciate it! The program I have to make: for example i write a sequence of numbers: {2,−4,5,1,0,−4} the program displays: {2,2,1,1,2,2}. So even numbers as 2, odd numbers as 1 if u write multiple numbers.

Thanks!
Last edited on
Hi sir,

could you show us what you did/tried?

PS: I love your work @ facebook :D
The only program closest to this, which I was able to make is this:

But how do I make it able to make it change even and odd numbers to 2 and 1 with multiple numbers in sequence?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  #include <iostream>
using namespace std;

int main() {
    int n;
    cout << "Enter an integer: ";
    cin >> n;
    if ( n%2 == 0) {
        cout << n << " 2.";
    }
    else {
        cout << n << " 1.";

    }
    return 0;
}
Last edited on
You have to use arrays

http://www.cplusplus.com/doc/tutorial/arrays/

Hope it helps
Last edited on
You don't have to use arrays.

The whole point is to be able to recognize whether a number is odd or even. This sounds like a job for... a function!

1
2
3
4
bool is_even( int n )
{
  return ...
}

Once you have that: for every number you input, check it against the function. If it is even, print a "2". If it is odd, print a "1".

Input may come directly from cin or some other file, or it may be from an array or some other sequence container (like a vector), etc.

Good luck.
Last edited on
Sorry, my bad

You may use arrays
up still can't do it..'
closed account (48T7M4Gy)
You need to include a while loop in you program. Check the tutorial on this site.
Topic archived. No new replies allowed.