I face the problem when i key in 5 5+ the result is 10.
But i key in 5 6+ he give the result 12.
Some equation can give me true result some give me false result.
Anyone can help me toubleshoot?
The following are my program:
[LIST=1]
[*]#include <iostream>
[*]#include <cctype>
[*]#include <string>
[*]#include "Stack.h"
[*]using namespace std;
[*]main()
[*]{
[*] char ch;
[*] string ch2;
[*] nodeIntType operand1, operand2, result;
[*] StackInt S;
[*] InitializeStack(&S);
[*] cout<<"Enter Postfix Expression :";
[*] cin.get(ch);
[*] while(ch !='\n'){
[*] if (isdigit(ch))
[*] {
[*] ch2=ch2+ch;
[*]
[*] }
[*] else if(ch==' ')
[*] {
[*] Push((nodeIntType)(atoi(ch2.c_str())),&S);
[*] ch2="";
[*] }
[*] else if(ch =='+' || ch=='-' || ch=='*' || ch=='/'){
[*] Pop (&S, &operand2);
[*] Pop (&S, &operand1);
[*] switch(ch){
[*] case '+':result = operand1 + operand2;
[*] break;
[*] case '-':result = operand1 - operand2;
[*] break;
[*] case '*':result = operand1 * operand2;
[*] break;
[*] case '/':result = operand1 / operand2;
[*] break;
[*] }
[*] Push(result, &S);
[*] }
[*] cin.get(ch);
[*] }
[*] Pop(&S , &result);
[*] cout<<"Answer :"<<result<<endl;
[*] return 0;
[*]}
[/LIST]