//this is the method
private bool isInt(string strInput)
{
int dataParse = 0;
if(int.TryParse(strInput, out dataParse) == true)
{
return true;
}
else
{
return false;
}
}
//This is the code
if (txtFirstNumber.TextLength > 0 && txtSecondNumber.TextLength > 0)
{
int exp = 0;
//Check that the second number is an integer
if (isInt(txtSecondNumber.Text) == true)
{
exp = Convert.ToInt32(txtSecondNumber.Text);
}
else //If it is not an integer, give an error
{
MessageBox.Show("Second number must be an integert value.", "Fault Error");
txtSecondNumber.Focus();
}
//If There is data, do the math
string output = "";
double result;
decimal firstnum = Convert.ToDecimal(txtFirstNumber.Text);
for (int i = 0; i < exp; i++)
{
result = Math.Pow((double)firstnum, (double)i);
output += firstnum.ToString() + " ^ " + i.ToString() + " = " + result.ToString() + Environment.NewLine;
}
txtResult.Text = output;
}
else
{
MessageBox.Show("Please input data");
}
//Disable the add and subtract buttons
btnAdd.Enabled = false;
btnSubtract.Enabled = false;