Need Help With Odd & Even Integers STACK

I Would Like The Program To Generate 15 Random Integers Into Array a, Then Push Both Even and Odd Integers Into One TEMP Stack. The Program Will Separate All Integers Into Odd & Even By Pulling Them Out In Incremental Order From The TEMP Stack. I Tried With The Even Integers First But The Program Did Not Display.

Could Someone Help Me Out, Please?
Much Appreciate In Advanced.

Here's The Program:
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
template <int n, class T>
class STACK
{
private: T ele[n];
		 int counter;
public: void ClearStack() 
		{
			counter = 0;
		}
		bool EmptyStack()
		{
			if (counter == 0)
				return true;
			else
				return false;
		}
		bool FullStack()
		{
			if (counter == n)
				return true;
			else
				return false;
		}
		void StackPush (T x)
		{
			ele[counter] = x;
			counter++;
		}
		T StackPop()
		{
			counter--;
			return ele[counter];
		}
};

int main ()
{
	//Declare Variables
		STACK <50, int> Even, Odd, Temp;
		
		//Clear All Stacks
		Even.ClearStack();
		Odd.ClearStack();
		Temp.ClearStack();

{
	int a[15];
	srand(time(0));

	//Assign 15 random Integers from 10 ~ 30
	cout<<"Random numbers generated are: ";
	for (int i = 0; i < 15; ++i)
	{
		i = rand()%11+20;
		Even.StackPush(a[i]);
		Odd.StackPush(a[i]);
		while (!Even.EmptyStack())
	{
		a[i] = Even.StackPop();
		Temp.StackPush(a[i]);
	}
	}
	cout<<endl;

	//Even Integers in array
	cout<<"Even integers in array a: ";
	
	for (int i = 0; i < 15; ++i)
	{
		if (i % 2 == 0)
		while (!Temp.EmptyStack())
	{
		a[i] = Temp.StackPop();
		
			cout<< a[i]<<"   ";
	}
	cout<<endl;
	}
/*
	//Odd Integers in array
	cout<<"Odd integers in array a: ";
	for (int i = 0; i < 15; ++i)
	{
		if (a[i] % 2 != 0)
			cout<< a[i]<<"   ";
	}
	cout<<endl;

	*/

	//Terminate Program
		system("pause");
		return 0;
}
}
Let's Begin With Getting The Integers Into The Array. So, Instead Of

1
2
 
i = rand() % 11 + 20;


We Use

1
2
 
a[i] = rand() % 11 + 20;


Last But Not Least, The Order Of Operations Matters.

1
2
3
4
5
6
7
 
    a[i] = Temp.StackPop();
        if (a[i] % 2 == 0)
	{
            Even.StackPush(a[i]);
	    cout<< a[i] << " ";
        }


I'm leaving the odd ones to you, sir. Share the fun.
Topic archived. No new replies allowed.