-3

App image

Hi guys, I'm a beginner in programming and I'm trying to make a math game. I don't know how to make a program calculate whats inside of the textbox. When player clicks a button with number or operator, app writes that in a textBox under the buttons. After clicking 'OK' app should compare number on the top(303) with players calculation. Any ideas how to make this work?

2 Answers2

1
using System;
using System.Data;

namespace EvaluateMathString_333737
{
    class Program
    {
        static void Main(string[] args)
        {
            string thestring = "3*8+5";
            Console.WriteLine(new DataTable().Compute(thestring, null));
            Console.ReadLine();
        }
    }
}
blaze_125
  • 2,262
  • 1
  • 9
  • 19
  • A nice albeit limited trick which may save op from even ever hearing about a math parser ;-) – TaW Jul 29 '19 at 21:01
0

I don't really understand the way that your game works but it seems you need to get the text and do some operation on it, I'd suggest you make different text fields for each input, it would make it easier for you.

you should know that the data entered inside the textfield is string and you have to parse it to int (or double/float if you want the number with point) after that you check the operation and then perform the operation.

Search for how to get a string from textfield and how to change string numbers to integer. hope this helps you

MoTahir
  • 863
  • 7
  • 22