I have a 10^x button.
I couldn't execute the function of 10^x Key to the textBox.
please help me with the C# Code for that Function.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted May 15, 2013, 6:09 AM
double result = Math.Pow(10, x);
textBox1.Text = result.ToString();
Bineesh ViswanathPosted May 15, 2013, 7:21 AM
VulpesPosted May 15, 2013, 6:40 AM
So, if 'x' is 2, the result will be 10^2 = 100.
If you're writing a calculator program, then I imagine the user will enter the value of 'x' in a textbox and then press the 10^x button to see the result displayed, either in the same or a different textbox.
If it's the same textbox, then you'd need code like this:
private void btnPower10_Click(object sender, EventArgs e)
{
double x;
if(!double.TryParse(textBox1.Text, out x))
{
MessageBox.Show("Textbox doesn't contain a valid number. Please amend.");
textBox1.Focus();
return;
}
double result = Math.Pow(10, x);
textBox1.Text = result.ToString();
}
Bineesh ViswanathPosted May 15, 2013, 6:33 AM