Hi, I'm trying to write a program that will take an infix notation postifx RPN. My problem is that I can't get it to print out the new equation if someone could try and help me out with that, Iit would be greatly appreciated.

#include <iostream>
#include <queue>
#include <stack>

using namespace std;

int main(){

stack<char> it;
queue<char> hold;
string input;

cout << "Please enter an equation" << endl;
cin >> input;

for(int i = 0; i < input.length(); i++){
char value = input.at(i);

while(it.empty() == true){
if(value >= 'A')
hold.push(value);
else{
if(value == '(')
it.push(value);
else if(value == ')')
while(it.top()!= '('){
hold.push(it.top());
it.pop();
}
else if(it.empty() == true || value == '*' ||value == '/' && !(it.top() == '*' || it.top() == '/'))
it.push(value);
else{
while(it.empty() == false && value == '+' || value == '-' || (value == '*' || value == '/') && (it.top() == '*' || it.top() =='/' )){
hold.push(it.top());
it.pop();

}
it.push(value);
}

}
}

}
while(it.empty() !=false)
{
hold.push(it.top());
it.pop();
}
while(hold.empty() == false)
{
hold.pop();
cout << hold.front() << endl;
}

cout << hold.front()<< endl;
}

1) Formatting - your code is too hard to follow without proper formatting
2) Based on the problem as stated - "I can't get it to print out the new equation" - use cout . If that's not helpful, try explaining the problem. Don't make us guess.

I'm sorry i wasn't clear I thought I was. And I'm a little new with programming so my formatting might be horrible, and I apoligize. My program is suppose to go through and look at any infix notation equation and print out a reverse polish notation equation. I have my program do this, but when I use the cout command to try and print out the new equation, it shows a blank line, and ends the program. I need it to actually print out the RPN equation. If you need anymore explaination let me know, and I will try to add more detail.

And I'm a little new with programming so my formatting might be horrible, and I apoligize.

Easily fixed with the link provided above.

My program is suppose to go through and look at any infix notation equation and print out a reverse polish notation equation. I have my program do this, but when I use the cout command to try and print out the new equation, it shows a blank line, and ends the program. I need it to actually print out the RPN equation. If you need anymore explaination let me know, and I will try to add more detail.

Then your RPN must not be created properly. Output values at key places in your program to make sure the values are as you expect. What values are being pushed, popped, tested, and so on? If they aren't correct, you need to figure out where it goes wrong. Add more cout 's

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.