Printing even and odd numbers in alternating pattern

Can somebody please help me with this??
We never really had a thorough discussion yet about if-else statements and while.. but our teacher already gave us a difficult assignment..

We should write a program the accepts a number , n, and displays the first n values of the number series:

the pattern to be print was like this
1 1 2 3 4 5 8 7 16 9 32 11 64 13...

alternating odd and even numbers using while and if-else statements

if you input n, the output will print only until 1 1 2 3 4 5 8 7

please, can anyone help me..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

using std::cout;

int main()
{
  int n;
  std::cin >> n;
  int i = 0;
  while (i < n) {
    if (i & 1) cout << i << ' ';
    else cout << (1 << (i >> 1)) << ' ';
    i++;
  }
}
Mr. Konstantin2.. thank you very much for the info..
Topic archived. No new replies allowed.