how to do calculations with InputField ?

I used following script

     public InputField BasePrice; //assign base price input field here
     public InputField SellingPrice; //assign selling price input field here
     public Text Profit; //assign profit text here  

     void cal()
     {
     int BP = Convert.ToInt32(BasePrice.text); // convert it into integer
     int SP = Convert.ToInt32(SellingPrice.text); // convert it into integer
     int P = SP-BP; // do the calculation, find the result
     Profit.text = P.ToString(); //turn result back into string and display it in the profit text
    }  

it looks like it should work but it doesnt. after I enter value in SP & BP and hit enter, nothing happenes. please help. thanks in advance.

Hi, I tried your code and it works for me. How are you calling the cal() function? You should create a button for example, so if you hit it it will call the function. Otherwise you could create a condition that if you hit the enter key it will call the function like:

    void Update()
    {
        if (Input.GetKeyDown("return"))
        {
            cal();
        }
    }

    void cal()
    {
        int BP = Convert.ToInt32(BasePrice.text); // convert it into integer
        int SP = Convert.ToInt32(SellingPrice.text); // convert it into integer
        int P = SP - BP; // do the calculation, find the result
        Profit.text = P.ToString(); //turn result back into string and display it in the profit text
    }