Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8911283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:54:14+00:00 2026-06-15T03:54:14+00:00

I am currently working with Reverse Polish Notation. I have able to perform all

  • 0

I am currently working with Reverse Polish Notation. I have able to perform all operation in exception of exponential math. I am aware that C# sharps performs exponential math with Math.Pow but using that in my code is giving me an error 'System.Collections.Generic.Stack<T>.Push(T)' is a 'method', which is not valid in the given context. You can find the specific issue in the last if else statement. Any idea how I can properly correct or create a way to perform exponential math?

Code

private string inputValue = "";

private void RPNCalc(string rpnValue)
{
Stack<int> stackCreated = new Stack<int>();
stackCreated.Clear();
string[] inputArray = rpnValue.Split();
int end = inputArray.Length - 1;
int numInput;
int i = 0;

do
{
    if ("=+-*/%^".IndexOf(inputArray[i]) == -1)
    {
        try
        {
            numInput = Convert.ToInt32(inputArray[i]);
            stackCreated.Push(numInput);
        }
        catch
        {
            MessageBox.Show("Please check the input");
        }
    }

        else if (inputArray[i]== "+")
        {
            try
            {
                int store1 = stackCreated.Pop();
                int store2 = stackCreated.Pop();
                stackCreated.Push(store2 + store1);
            }
            catch
            {
            }
        }

        else if (inputArray[i]== "-")
        {
            try
            {
                int store1 = stackCreated.Pop();
                int store2 = stackCreated.Pop();
                stackCreated.Push(store2 - store1);
            }
            catch
            {
            }
        }

        else if (inputArray[i]== "%")
        {
            try
            {
                int store1 = stackCreated.Pop();
                int store2 = stackCreated.Pop();
                stackCreated.Push(store2 % store1);
            }
            catch
            {
            }
        }

        else if (inputArray[i]== "*")
        {
            try
            {
                int store1 = stackCreated.Pop();
                int store2 = stackCreated.Pop();
                stackCreated.Push(store2 * store1);
            }
            catch
            {
            }
        }

        else if (inputArray[i]== "/")
        {
            try
            {
                int store1 = stackCreated.Pop();
                int store2 = stackCreated.Pop();
                stackCreated.Push(store2 / store1);
            }
            catch
            {
            }
        }

        else if (inputArray[i] == "^")
        {
            try
            {
                int store1 = stackCreated.Pop();
                int store2 = stackCreated.Pop();
                stackCreated.Push.Math.Pow(store1, store2);
            }
            catch
            {
            }
        }

}
while(i++ < end && inputArray[i]!= "=" && stackCreated.Count != 0);
string result = inputValue + " " + stackCreated.Pop().ToString() + Environment.NewLine;
TxtOutputBox.AppendText(result);
TxtInputBox.Clear();

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:54:15+00:00Added an answer on June 15, 2026 at 3:54 am

    Should be:

    stackCreated.Push((int)Math.Pow(store1, store2));
    

    This will perform the power operation, and then push the result onto the stack.

    Its like doing:

    int tmp = (int)Math.Pow(store1, store2);
    stackCreated.Push(tmp);
    

    Also note that Math.Pow works on doubles. Your ints (store1 and store2) will be automatically converted up to a double, but you need to tell the compiler to cast the result back down to an int.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working with a reverse polish notation calculator. It is fully functional
I am a novice C# coder and currently working on a Reverse polish notation
I am currently working on an application that allows reverse geocoding using silverlight +
All, I have been practicing coding problems online. Currently I am working on a
Currently working with converting SQLException error messages into messages that are more useful for
Im currently working on a game that uses multi touch to apply zoom to
Am currently working on an application that requires users to submit posts and comments
I am working on an app that will show reverse view from camera. For
I have a specific scenario that I want to solve. I currently connect to
I have been working on a shop that is built in Python on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.