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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted May 15, 2013, 2:09 AM EDT
double result = Math.Pow(10, x);
textBox1.Text = result.ToString();
Bineesh ViswanathRank #1,681 · 907 reputationPosted May 15, 2013, 2:33 AM EDT
VulpesRank #55 · 29.2K reputationPosted May 15, 2013, 2:40 AM EDT
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 ViswanathRank #1,681 · 907 reputationPosted May 15, 2013, 3:21 AM EDT