Evaluate postfix expressions

in a .txt file

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

38 Replies - 9132 Views - Last Post: 17 October 2010 - 12:50 PM Rate Topic: -----

#1 qwert12345   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 169
  • Joined: 26-October 08

Evaluate postfix expressions

Posted 08 October 2010 - 01:00 PM

Evaluate a postfix expression containing some one-letter variables a-z (lower case)
whose values are given in a data file called: 375_stack_prog.txt.
there will not be more than 26 variables (a-z) and
there will not be more than 20 postfixes

use a stack of integers and the algorithm below.
algorithm for a given postfix expression
scan the postfix left to right char by char
if char is operand (var)
find its value and push on stack
if char is operator (+ - / *)
get the value from the top of the stack (say Value A) and pop the stack
again get the top of the stack (say Value B) and pop the stack
compute "B operator A" and push the result on stack
if there is a stack problem during any of the above operations
report "invalid postfix" and return
if there is 0 divide problem
report "0 divide problem" and return
if char is neither operand nor operator
report invalid variable and return

at the end of scanning the postfix,
if stack contains exactly one entry return this value
else report invalid postfix and return
end of algorithm


sample data file: (c:\temp\375_stack_prog3_data.txt)
the first line gives how many variables there are (say n variables)
the next n lines are the variables and their values separated by a space
the rest of the lines are the postfix expressions that you will evaluate.

I'm having some compiler errors in my code: I put //compiler error...by each line of code that is causing a compiler error.

And I attached the data.txt that is needed to test my program.

In 375StackProg3Data.txt:
5
a 4
d 9
z 17
y 0
x 2
ad+
ad+zy-x/*
xz*yd+ad-*+
ab+++
ad*yz*+ad*yz*-*
adz*+yx/-
zy/
abx^+


And the expected output for my program should look like this:

a =4
d =9
z =17
y =0
x =2
ad+ =13
ad+zy-x/* =104
xz*yd+ad-*+ =-11
ab+++ is invalid postfix ERROR
ad*yz*+ad*yz*-* = 1296
adz*+yx/- =157
zy/ zero divide ERROR
adx^+ is invalid postfix ERROR



#include <iostream>
#include <iomanip> 
#include <stack>
#include <fstream>
#include <string>

using namespace std;

#define MAX 26 // Max Number of Variables and Postfixes

string Variables = "abcedfghijklmnopqrstuvwxyz"; //Possible Variable Names

int Values[26] = {0};

string Postfix;

int NumberofVariables;

int NumberofPostfixes;

int Index;

int ValueA;

int ValueB;

stack <int> STK;

int ReadFile();

int VariableToIndex(string Variables);

bool CheckForOperand(string Variables);

bool CheckForOperator(string Variables);

int ProcessThePostfix(string Postfix, int NumberofPostfixes);







int main ()
{
    
int CheckOperand;

int CheckOperator;

CheckOperand = CheckForOperand(Variables);

CheckOperator = CheckForOperator(Variables);

NumberofPostfixes = ReadFile();
    
      for(int i = 0; i < NumberofPostfixes ; i++)
         {
            cout << NumberofPostfixes;  //display the output of the postfixes.
         

       

     if(CheckOperator = true)
       {
          ValueA = STK.top();
          
          STK.pop();
          
          ValueB = STK.top();
          
          STK.pop();
          
          
          
       } 
       
       if(CheckOperand = true)
       {
          STK.push(Values[i]);
          
          ProcessThePostfix(Postfix, NumberofPostfixes);
          
       }
         cout << "  =  " << STK.top();
       }
         
    

cin.ignore();
cin.get();
}

int ReadFile()
{
  int Count = 0; 
  
  int i = 0;
  
  int Temp; 
  
  ifstream Data;
  
  Data.open("C:375StackProg3Data.txt");    
  
  Data >> Temp; 
    for(int j = 0; j < Temp ; i++)
       {
         Data >> Variables >> Values; //compiler error
         
         Variables = Variables + Values;//compiler error
         
         Values[j] = Values;//compiler error
           
         cout << Variables[j]<< " = " << Values[j] << endl; 
              
         Index = VariableToIndex(Variables);
         
         Values[Temp] = Values;//compiler error
       }
   while(Data >> Postfix[i])
       {
         i++;
       }
   
Count = i;

Data.close(); 
    
return Count; 
           
    
    if(!Data)
         {
           cout << "ERROR: Can't find 375StackProg3Data.txt" << endl; 
           exit(0);  
         }
    
  
}

int VariableToIndex(string Variables)
{

 if((Index >= 0) && (Index < Variables.length()))  
    {
      return Index;
    }
 else
    {
      cout << "ILLEGAL Variable" << endl;
      return -1;
    }

}

int IndexToVariable(int Index)
{
Index = Variables.find(Variables);
    if((Index >= 0) && (Index < Variables.substr(Index, 1)) )//compiler error 
    {
      return Index;
    }
 else
    {
      cout << "ILLEGAL Variable" << endl;
      return -1;
    }
    
}

bool CheckForOperand(string Variables)
{
   if((Variables >="a") && (Variables <="z")) 
    {
       return true; 
    }  
   else
   {
   cout << " INVALID Postfix Error" << endl;
       return false; 
    }  
}

bool CheckForOperator(string Variables)
{
     if(Variables = "+" || Variables = "-" || Variables = "*" || Variables = "/" )//compiler error
    {
       return true; 
    }  
     else
   {  
       return false; 
    }  
     
}

int ProcessThePostfix(string Postfix, int NumberofPostfixes)
{
  int Math;
  
  for(int i = 0; i < NumberofPostfixes ; i++) 
    {
  
      Math = Postfix[i];
  
      switch(Math)
        {
          case '+': Values[i] = ValueA + ValueB;
          return Values[i];
          break;
     
          case '-': Values[i] = ValueB - ValueA;
          return Values[i];
          break;
     
          case '*': Values[i] = ValueA * ValueB;
          return Values[i];
          break;

          case '/': if(ValueB != 0)
                     {
                        Values[i] = ValueA / ValueB;
                        return Values[i];
                        break;
                     }
                    if(ValueB = 0) 
                     {
                      cout << "ERROR: 0 Divide Problem" << endl;
                      return -1;
                      break;
                     }
          
          default: cout << "Invaild Postfix" << endl;
          
          
       }
     }
   }


Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: Evaluate postfix expressions

#2 seeP+   User is offline

  • D.I.C Addict

Reputation: 55
  • View blog
  • Posts: 601
  • Joined: 20-July 09

Re: Evaluate postfix expressions

Posted 08 October 2010 - 01:56 PM

Post the error reports. Check if the file is open.
Was This Post Helpful? 0
  • +
  • -

#3 mojo666   User is offline

  • D.I.C Addict
  • member icon

Reputation: 409
  • View blog
  • Posts: 885
  • Joined: 27-June 09

Re: Evaluate postfix expressions

Posted 08 October 2010 - 02:08 PM

See comments.

View Postqwert12345, on 08 October 2010 - 12:00 PM, said:

int ReadFile()
{
  int Count = 0; 
  
  int i = 0;
  
  int Temp; 
  
  ifstream Data;
  
  Data.open("C:375StackProg3Data.txt");    
  
  Data >> Temp; 
    for(int j = 0; j < Temp ; i++)
       {
         Data >> Variables >> Values; //I dont know whats wrong with this one.
         
         Variables = Variables + Values;//what do you think string+array will do?
         
         Values[j] = Values;//same problem.  int=array will do what?
           
         cout << Variables[j]<< " = " << Values[j] << endl; 
              
         Index = VariableToIndex(Variables);
         
         Values[Temp] = Values;//same as above.
       }
   while(Data >> Postfix[i])
       {
         i++;
       }
   
Count = i;

Data.close(); 
    
return Count; //Nothing after this line will be executed.
           
    
    if(!Data)
         {
           cout << "ERROR: Can't find 375StackProg3Data.txt" << endl; 
           exit(0);  
         }
    
  
}


Was This Post Helpful? 1
  • +
  • -

#4 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6260
  • View blog
  • Posts: 24,030
  • Joined: 23-August 08

Re: Evaluate postfix expressions

Posted 08 October 2010 - 02:20 PM

if(CheckOperator = true)

that's an assignment, not a comparison.
Was This Post Helpful? 0
  • +
  • -

#5 qwert12345   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 169
  • Joined: 26-October 08

Re: Evaluate postfix expressions

Posted 08 October 2010 - 02:23 PM

View PostseeP+, on 08 October 2010 - 12:56 PM, said:

Post the error reports. Check if the file is open.

Error Messages in the ReadFile();

Data >> Variables >> Values;

no match for 'operator>>' in 'std::operator>> [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((std::basic_istream<char, std::char_traits<char> >&)((std::basic_istream<char, std::char_traits<char> >*)(&Data))), ((std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)(&Variables))) >> Values'

Variables = Variables + Values;

no match for 'operator+' in 'Variables + Values'

Values[j] = Values;

invalid conversion from `int*' to `int'

Values[Temp] = Values;

invalid conversion from `int*' to `int'

Error Messages in IndexToVariable()function:

 
if((Index >= 0) && (Index < Variables.substr(Index, 1)) ) 
    {
      return Index;
    }


no match for 'operator<' in 'Index < std::basic_string<_CharT, _Traits, _Alloc>::substr(typename _Alloc::size_type, typename _Alloc::size_type) const [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((unsigned int)Index), 1u)'


Error Messages in CheckForOperator(); function:

 
if(Variables = "+" || Variables = "-" || Variables = "*" || Variables = "/" )
    {
       return true; 
    }  


no match for 'operator||' in '"+" || Variables'
no match for 'operator||' in '"-" || Variables'
no match for 'operator||' in '"*" || Variables'
Was This Post Helpful? 0
  • +
  • -

#6 qwert12345   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 169
  • Joined: 26-October 08

Re: Evaluate postfix expressions

Posted 08 October 2010 - 04:08 PM

Ok, so I tried to have a temp. string for the variables and a temp int for the values in my ReadFile(); function...to store the data from the .txt file.

int ReadFile()
{
  string TempVariables;
  
  int TempValues;
 
  int Count = 0; 
  
  int i = 0;
  
  int Temp; 
  
  ifstream Data;
  
  Data.open("C:375StackProg3Data.txt");    
  
  Data >> Temp; 
    for(int j = 0; j < Temp ; j++)
       {
         Data >> TempVariables >> TempValues;
         
         
         Variables = Variables + TempVariables;
         
         TempValues[j] = Values;
           
         cout << Variables[j]<< " = " << Values[j] << endl; 
              
         Index = VariableToIndex(Variables);
         
        // TempValues[Temp] = TempValues;
       }
   while(Data >> Postfix[i])
       {
         i++;
       }
   
Count = i;

Data.close(); 
    
return Count; 
           
    
    if(!Data)
         {
           cout << "ERROR: Can't find 375StackProg3Data.txt" << endl; 
           exit(0);  
         }
    
  
}


Was This Post Helpful? 0
  • +
  • -

#7 seeP+   User is offline

  • D.I.C Addict

Reputation: 55
  • View blog
  • Posts: 601
  • Joined: 20-July 09

Re: Evaluate postfix expressions

Posted 08 October 2010 - 04:08 PM

Majority of your errors seem to be the caused by misusing variables.
1    Data >> Variables >> Values;

Values is an array. Here your trying to add a line to the address of the array.
Variables = Variables + Values;

Once again treat Values like an array. Since Values is an array of integers you need to convert them to strings
if you want to concatenate them and Variables into Variables.
Make sure your correctly using the array through out the program, recompile, and if any, post new errors.
Was This Post Helpful? 0
  • +
  • -

#8 qwert12345   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 169
  • Joined: 26-October 08

Re: Evaluate postfix expressions

Posted 08 October 2010 - 04:13 PM

that fixed almost all of the compiler errors in my ReadFile(); except

 TempValues[j] = Values;

invalid types `int[int]' for array subscript
Was This Post Helpful? 0
  • +
  • -

#9 seeP+   User is offline

  • D.I.C Addict

Reputation: 55
  • View blog
  • Posts: 601
  • Joined: 20-July 09

Re: Evaluate postfix expressions

Posted 08 October 2010 - 04:15 PM

Values in an array also so it needs a subscript.
Was This Post Helpful? 0
  • +
  • -

#10 qwert12345   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 169
  • Joined: 26-October 08

Re: Evaluate postfix expressions

Posted 08 October 2010 - 04:47 PM

I fixed the compiler error in my CheckForOperator(); function.
So, the last compiler error is this:

Error Messages in IndexToVariable()function:

1	if((Index >= 0) && (Index < Variables.substr(Index, 1)) )
2	    {
3	      return Index;
4	    }


no match for 'operator<' in 'Index < std::basic_string<_CharT, _Traits, _Alloc>::substr(typename _Alloc::size_type, typename _Alloc::size_type) const [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((unsigned int)Index), 1u)'

My code so far:
  



#include <iostream>
#include <iomanip> 
#include <stack>
#include <fstream>
#include <string>

using namespace std;

#define MAX 26 // Max Number of Variables and Postfixes

string Variables = "abcedfghijklmnopqrstuvwxyz"; //Possible Variable Names

int Values[26] = {0};

string Postfix;

int NumberofVariables;

int NumberofPostfixes;

int Index;

int ValueA;

int ValueB;

stack <int> STK;

int ReadFile();

int VariableToIndex(string Variables);

bool CheckForOperand(string Variables);

bool CheckForOperator(string Variables);

int ProcessThePostfix(string Postfix, int NumberofPostfixes);







int main ()
{
    
int CheckOperand;

int CheckOperator;

CheckOperand = CheckForOperand(Variables);

CheckOperator = CheckForOperator(Variables);

NumberofPostfixes = ReadFile();
    
      for(int i = 0; i < NumberofPostfixes ; i++)
         {
            cout << NumberofPostfixes;  //display the output of the postfixes.
         

       

     if(CheckOperator == true)
       {
          ValueA = STK.top();
          
          STK.pop();
          
          ValueB = STK.top();
          
          STK.pop();
          
          
          
       } 
       
       if(CheckOperand == true)
       {
          STK.push(Values[i]);
          
          ProcessThePostfix(Postfix, NumberofPostfixes);
          
       }
         cout << "  =  " << STK.top();
       }
         
   

cin.ignore();
cin.get();
}

int ReadFile()
{
  string TempVariables;
  
  int TempValues;
 
  int Count = 0; 
  
  int i = 0;
  
  int Temp; 
  
  ifstream Data;
  
  Data.open("C:375StackProg3Data.txt");    
  
  Data >> Temp; 
    for(int j = 0; j < Temp ; j++)
       {
         Data >> TempVariables >> TempValues;
         
         //Data >> Values;
         
         Variables = Variables + TempVariables;
         
         TempValues = Values[j];
           
         cout << Variables[j]<< " = " << Values[j] << endl; 
              
         Index = VariableToIndex(Variables);
         
        // TempValues[Temp] = TempValues;
       }
   while(Data >> Postfix[i])
       {
         i++;
       }
   
Count = i;

Data.close(); 
    
return Count; 
           
    
    if(!Data)
         {
           cout << "ERROR: Can't find 375StackProg3Data.txt" << endl; 
           exit(0);  
         }
    
  
}

int VariableToIndex(string Variables)
{

 if((Index >= 0) && (Index < Variables.length()))  
    {
      return Index;
    }
 else
    {
      cout << "ILLEGAL Variable" << endl;
      return -1;
    }

}

int IndexToVariable(int Index)
{
Index = Variables.find(Variables);
    if((Index >= 0) && (Index < Variables.substr(Index, 1)) ) 
    {
      return Index;
    }
 else
    {
      cout << "ILLEGAL Variable" << endl;
      return -1;
    }
    
}

bool CheckForOperand(string Variables)
{
   if((Variables >="a") && (Variables <="z")) 
    {
       return true; 
    }  
   else
   {
   cout << " INVALID Postfix Error" << endl;
       return false; 
    }  
}

bool CheckForOperator(string Variables)
{
     if((Variables == "+" )|| (Variables == "-" )|| (Variables == "*" )|| (Variables == "/") )
    {
       return true; 
    }  
     else
   { 
     cout << " INVALID Postfix Error" << endl;     
       return false; 
    }  
     
}

int ProcessThePostfix(string Postfix, int NumberofPostfixes)
{
  int Math;
  
  for(int i = 0; i < NumberofPostfixes ; i++) 
    {
  
      Math = Postfix[i];
  
      switch(Math)
        {
          case '+': Values[i] = ValueA + ValueB;
          return Values[i];
          break;
     
          case '-': Values[i] = ValueB - ValueA;
          return Values[i];
          break;
     
          case '*': Values[i] = ValueA * ValueB;
          return Values[i];
          break;

          case '/': if(ValueB != 0)
                     {
                        Values[i] = ValueA / ValueB;
                        return Values[i];
                        break;
                     }
                    if(ValueB = 0) 
                     {
                      cout << "ERROR: 0 Divide Problem" << endl;
                      return -1;
                      break;
                     }
          
          default: cout << "Invaild Postfix" << endl;
          
          
       }
     }
   }


This post has been edited by qwert12345: 08 October 2010 - 04:51 PM

Was This Post Helpful? 0
  • +
  • -

#11 seeP+   User is offline

  • D.I.C Addict

Reputation: 55
  • View blog
  • Posts: 601
  • Joined: 20-July 09

Re: Evaluate postfix expressions

Posted 08 October 2010 - 09:08 PM

Your trying to compare an int with a string. Substr() returns a string.
Substr()

This post has been edited by seeP+: 08 October 2010 - 09:08 PM

Was This Post Helpful? 0
  • +
  • -

#12 qwert12345   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 169
  • Joined: 26-October 08

Re: Evaluate postfix expressions

Posted 09 October 2010 - 10:24 AM

View PostseeP+, on 08 October 2010 - 08:08 PM, said:

Your trying to compare an int with a string. Substr() returns a string.
Substr()


Ok, so this is the new IndexToVariable(); function:
int IndexToVariable(int Index)
{
Index = Variables.find(Variables);
    if((Index >= 0) && (Index < 26 ) ) 
    {
      return Variables.substr(Index, 1);//compiler error
    }
 else
    {
      cout << "ILLEGAL Variable" << endl;
      return -1;
    }
    
}




The compiler error is this: cannot convert std::basic_string<char, std::char_traits<char>, std::allocator<char> >' to `int' in return
Was This Post Helpful? 0
  • +
  • -

#13 seeP+   User is offline

  • D.I.C Addict

Reputation: 55
  • View blog
  • Posts: 601
  • Joined: 20-July 09

Re: Evaluate postfix expressions

Posted 09 October 2010 - 06:50 PM

View Postqwert12345, on 09 October 2010 - 09:24 AM, said:

View PostseeP+, on 08 October 2010 - 08:08 PM, said:

Your trying to compare an int with a string. Substr() returns a string.
Substr()


Ok, so this is the new IndexToVariable(); function:
int IndexToVariable(int Index)
{
Index = Variables.find(Variables);
    if((Index >= 0) && (Index < 26 ) ) 
    {
      return Variables.substr(Index, 1);//compiler error
    }
 else
    {
      cout << "ILLEGAL Variable" << endl;
      return -1;
    }
    
}




The compiler error is this: cannot convert std::basic_string<char, std::char_traits<char>, std::allocator<char> >' to `int' in return

Substr() returns a string. Your return type of that function is an integer.

This post has been edited by seeP+: 09 October 2010 - 06:51 PM

Was This Post Helpful? 0
  • +
  • -

#14 qwert12345   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 169
  • Joined: 26-October 08

Re: Evaluate postfix expressions

Posted 09 October 2010 - 08:50 PM

int IndexToVariable(int Index); is now
string IndexToVariable(int Values[]);

compiler error for this line of code int main();:
PrintVal = IndexToVariable(Values[i]);


invalid conversion from `int' to `int*'

My code so far:
#include <iostream>
#include <iomanip> 
#include <stack>
#include <fstream>
#include <string>

using namespace std;

#define MAX 26 // Max Number of Variables and Postfixes

string Variables = "abcedfghijklmnopqrstuvwxyz"; //Possible Variable Names

int Values[26] = {0};

string Postfix;

int NumberofVariables;

int NumberofPostfixes;

int Index;

int ValueA;

int ValueB;

stack <int> STK;

int ReadFile();

int VariableToIndex(string Variables);

string IndexToVariable(int Values[]);

bool CheckForOperand(string Variables);

bool CheckForOperator(string Variables);

int ProcessThePostfix(string Postfix, int NumberofPostfixes);







int main ()
{
    
int CheckOperand;

int CheckOperator;

CheckOperand = CheckForOperand(Variables);

CheckOperator = CheckForOperator(Variables);

NumberofPostfixes = ReadFile();

string PrintVar;

string PrintVal;
    
      for(int i = 0; i < NumberofPostfixes ; i++)
      
         {
           PrintVar = VariableToIndex(Variables);
           PrintVal = IndexToVariable(Values[i]); //compiler  error
            cout << PrintVar << " = " << PrintVal;  //display the output of the postfixes.
            
         

       

     if(CheckOperator == true)
       {
          ValueA = STK.top();
          
          STK.pop();
          
          ValueB = STK.top();
          
          STK.pop();
          
          
          
       } 
       
       if(CheckOperand == true)
       {
          STK.push(Values[i]);
          
          ProcessThePostfix(Postfix, NumberofPostfixes);
          
       }
         cout << "  =  " << STK.top();
       }
         
    

cin.ignore();
cin.get();
}

int ReadFile()
{
  string TempVariables;
  
  int TempValues;
 
  int Count = 0; 
  
  int i = 0;
  
  int Temp; 
  
  ifstream Data;
  
  Data.open("C:375StackProg3Data.txt");    
  
  Data >> Temp; 
    for(int j = 0; j < Temp ; j++)
       {
         Data >> TempVariables >> TempValues;
         
         //Data >> Values;
         
         Variables = Variables + TempVariables;
         
         TempValues = Values[j];
           
         cout << Variables[j] << " = " << Values[j] << endl; 
              
         Index = VariableToIndex(Variables);
         
        // TempValues[Temp] = TempValues;
       }
   while(Data >> Postfix[i])
       {
         i++;
       }
   
Count = i;

Data.close(); 
    
return Count; 
           
    
    if(!Data)
         {
           cout << "ERROR: Can't find 375StackProg3Data.txt" << endl; 
           exit(0);  
         }
    
  
}

int VariableToIndex(string Variables)
{
Index = Variables.find(Variables);    

 if((Index >= 0) && (Index < Variables.length()))  
    {
      return Index;
    }
 else
    {
      cout << "ILLEGAL Variable" << endl;
      return -1;
    }

}

string IndexToVariable(int Values[])
{

    if((Index >= 0) && (Index < 26 ) ) 
     {  
        return Variables.substr(Index,1);
     }
    else
     {
      cout << "ILLEGAL Variable" << endl;
      //return -1;
   }
    
}

bool CheckForOperand(string Variables)
{
   if((Variables >="a") && (Variables <="z")) 
    {
       return true; 
    }  
   else
   {
   cout << " INVALID Postfix Error" << endl;
       return false; 
    }  
}

bool CheckForOperator(string Variables)
{
     if((Variables == "+" )|| (Variables == "-" )|| (Variables == "*" )|| (Variables == "/") )
    {
       return true; 
    }  
     else
   { 
     cout << " INVALID Postfix Error" << endl;     
       return false; 
    }  
     
}

int ProcessThePostfix(string Postfix, int NumberofPostfixes)
{
  int Math;
  
  for(int i = 0; i < NumberofPostfixes ; i++) 
    {
  
      Math = Postfix[i];
  
      switch(Math)
        {
          case '+': Values[i] = ValueA + ValueB;
          return Values[i];
          break;
     
          case '-': Values[i] = ValueB - ValueA;
          return Values[i];
          break;
     
          case '*': Values[i] = ValueA * ValueB;
          return Values[i];
          break;

          case '/': if(ValueB != 0)
                     {
                        Values[i] = ValueA / ValueB;
                        return Values[i];
                        break;
                     }
                    if(ValueB = 0) 
                     {
                      cout << "ERROR: 0 Divide Problem" << endl;
                      return -1;
                      break;
                     }
          
          default: cout << "Invaild Postfix" << endl;
          
          
       }
     }
   }




This post has been edited by qwert12345: 09 October 2010 - 08:52 PM

Was This Post Helpful? 0
  • +
  • -

#15 seeP+   User is offline

  • D.I.C Addict

Reputation: 55
  • View blog
  • Posts: 601
  • Joined: 20-July 09

Re: Evaluate postfix expressions

Posted 09 October 2010 - 08:56 PM

PrintVal = IndexToVariable(Values[i]);

That is not how you pass an array to a function.
Arrays
Was This Post Helpful? 1
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3