Program goal: user input for 2 equations to evaluate the operator signs. i.e. 1 * 2 + 4 - 4
and 5 - 2 * 6 + 9 would be the same --> " * + - " in both, order does not matter.

Output: cout saying match or not match.

I'm not sure how to go about checking the operators in the best/easiest fashion, in the main(), or in my cpp file where 90% of the "work" is happening. I've tried all "i" know to do. Obviously I'm missing something, and/or went about this program totally abstract. But, I am basically teaching myself and slightly struggling. So.. he's the code:

stack s1;
    stack s2;
    char ch1=NULL

		cout << "stack currently empty...\n" << endl;  // check if stack is empty

    cout << "enter first set: ";
	while ((ch1 = cin.get())!= '\n'){
		if (!s1.full()) s1.push(ch1,ch2);
	while (!s1.empty())
		cout << s1.pop();
	}//end whiles s1
    cout << "\nenter second set: ";
	while ((ch2 = cin.get())!= '\n'){
		if (!s2.full()) s2.push(ch1,ch2);}
	while (!s2.empty()){
		cout <<  s2.pop();
	}//end whiles s2
// not a good place to check I'm thinking...
void stack::push(int a,int b) {
	char p ='+',
	s= '-',
	m = '*',
	d = '/',
	e = '=';
   char pp ='+',
	ss = '-',
	mm = '*',
	dd = '/',
	ee = '=';

	if(a == p){
		cout << p;

	if(a == s){
		cout << s;

	if(a == m){
		cout << m;

	if(a == d){
		cout << d;

	if(a == e){
		cout << e;
   if int a, int b operator seperator
	if(b == pp){
		cout << pp; 

	if(b == ss){
		cout << ss;

	if(b == mm){
		cout << mm;

	if(b == dd){
		cout << dd;

	if(b == ee){
		cout << ee;

//better place to is a different story.

}// end stack::push

Why do you have to name all of the operators? Can't you just push all operators from each string into two stacks and then compare the elements of the stacks? I suggest you hard code two strings, parse them into the two stacks, and then output the contents of the stacks. If this works properly, then you just need to compare corresponding elements and if all of the comparisons are true then the operators are the same and in the same order.

This article has been dead for over six months. Start a new discussion instead.