Operator ‘

You need to convert the value entered to a number before comparing it:

    private void button1_Click(object sender, EventArgs e)
    { 
        var number = Double.Parse(textBox1.Text);
        if (number <= numbera)
        {
            label1.Text = ("Customer can receive  £5 off purchase");
        }
        else if (number <= numberb)
        {
            label1.Text = ("Customer can receive  £10 off purchase");
        }
    }

You should notice that code will break whenever the user enters something like “abc”, as that can’t be parsed as number, so you’ll need to work with a more safer way to validate the user input like Double.TryParse.

Leave a Comment