-1

I'm fairly new to programming and c#. I have a problem with a simple calculator program I'm trying to write in visual studio c#. I want to convert my text with numbers and math operators into a number. All my attempts so far have led to no success. I have tried:

  • Double.Parse()
  • Convert.Int32()
  • Convert.Double()

Here are some images of my code: Pic One Pic Two

Any help would be much appreciated, if there is any extra information you need I would be happy to provide it.

-Retro_Goat

1 Answers1

-1

For Pic 1 C# can not take an equation string and convert it to a result, it can take values in an equation form and convert it to a result, i.e.

int val = Convert.ToInt32((7 + 3) * 3.5);

If you have an equation string you will need to cycle through the string an separate the values and the operations and process them as values or use a processing object, see StackOverflow link

For Pic 2

        double val = 0;
        if(double.TryParse(lblDisplay.Text, out val))
        {
            // val is set to the string value
        }
        else 
        {
           // The string was not a valid number
        }
Xavier
  • 1,383
  • 7
  • 6