Even and odd numbers

I have got the programs to print out even numbers between two numbers. May anyone tell me how I can print out odd numbers in that while loop?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
	//Declare a number the user will enter
	int number1;
	int number2;
	int even;
	int odd;

	//Tell user to enter a number
	cout<<"\n\tEnter in two numbers: ";
	cin>>number1;
	cout<< " " ;
	cin>>number2;

	
	//whle loop
	if (number2<number1)
	{
		cout<<"number 2 will now be ";
		number2=number1;
		number1=number2;
		cout<<number2;
	}

	//Declare a counter to calculate even number

	int counter;
	counter=0;
	cout<<"even: ";
	while (number1<number2)
	{	
		if(number1%2==0)
		{
			even=number1+2;
			cout <<even << " " ;
		}
		number1++;
	}

	//Display on the screen that even numbers are calculated
cout<<"Even numbers are calculated";


	cout<<"DONE";
	_getch();
	return 0;
}

Odd is the opposite of even so just throw in an else statement.

ex:

1
2
3
4
5
6
7
8
if( number1 % 2 == 0 )
{
    //output the stuff because its even
}
else
{
    //output stuff because it is odd
}
Topic archived. No new replies allowed.