Sign in with
Sign up | Sign in
Your question
Solved

C# How to do a math operation with one button and one text box?

Last response: in Applications
Share
September 6, 2012 11:46:56 PM

This is for school.

I want to be able to able to type a number into a text box click a button, then type another number into the same text box click a button and apply a math operation to those two numbers(In visual studio 2010 C#). Now, I don't have any trouble with the math operations, but I have no idea how to prepare for it. We have only been taught to do the operations when there were multiple boxes, by storing the values into a variable converting it, adding the two integers then converting back. I thought maybe using arrays? But we have only been taught if then statements,while loops, and bools.




This is what I have. We need to show the number of values that were put in, which is why I have number++;





public partial class frmtemp : Form
{

int number=0;






public frmtemp()
{
InitializeComponent();
}

private void frmtemp_Load(object sender, EventArgs e)
{

}

private void txt1_TextChanged(object sender, EventArgs e)
{




}

private void frmtemp_FormClosing(object sender, FormClosingEventArgs e)
{


MessageBox.Show("Numbers Added: "+number.ToString());

this.DialogResult = DialogResult.OK;




}

private void btntemp_Click(object sender, EventArgs e)
{

number++;
a b L Programming
September 7, 2012 1:24:18 AM

Yup, school has started and now here come the "please do my assignment for me" posts.
September 7, 2012 1:33:14 AM

oh sorry didn't want to come off like that, at this point I just want to know if it is possible using bools,while loops, and if then statements.
Related resources

Best solution

a b L Programming
September 7, 2012 2:00:11 AM
Share

An array is the cleanest way to do it.
September 7, 2012 2:48:45 AM

Best answer selected by austinedwards7.
!