Calculator with sin, cos, tan, please help!!

Hi!!!

I have to create a calculator with +,-,*,/, +/- ,clear, sin,cos,tan,mod.
I have working +,-,*,/,+/- and clear.
Can anybody told me how can I make work sin, cos, ta, mod?

here is what I have so far:


bool plus = false;
bool minus = false;
bool multiply = false;
bool divide = false;
bool modulus = false;


public Form1()
{
InitializeComponent();

//buttom 0-9
}

private void bt1_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "1";

}

private void bt2_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "2";
}

private void bt3_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "3";
}

private void bt4_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "4";
}

private void bt5_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "5";
}

private void bt6_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "6";
}

private void bt7_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "7";
}

private void bt8_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "8";
}

private void bt9_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "9";
}

private void bt_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "0";
}


//buttom +/-

private void btNegative_Click(object sender, EventArgs e)
{
if (textBox1.Text.Contains("-"))
{
textBox1.Text = textBox1.Text.Remove(0, 1); //Remove "-" if it is
already in the text box
}
else
{
textBox1.Text = "-" + textBox1.Text;
}


}

//buttom +

private void btPlus_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
return;
}
else
{
plus = true; //we make the 'adding' true
textBox1.Tag = textBox1.Text; // storage the number
textBox1.Text = ""; //clear the text box
}

}

//buttom =



private void btequal_Click(object sender, EventArgs e)
{
if (plus)
{
decimal dec = Convert.ToDecimal(textBox1.Tag)+ Convert.ToDecimal(textBox1.Text);

textBox1.Text = dec.ToString();
}
if (multiply)
{
decimal dec = Convert.ToDecimal(textBox1.Tag) * Convert.ToDecimal(textBox1.Text); //will multiply the two values
textBox1.Text = dec.ToString();
}
if (minus)
{
decimal dec = Convert.ToDecimal(textBox1.Tag) - Convert.ToDecimal(textBox1.Text); //will substract the two values
textBox1.Text = dec.ToString();
}
if (divide)
{
decimal dec = Convert.ToDecimal(textBox1.Tag) / Convert.ToDecimal(textBox1.Text); //will divide the two values
textBox1.Text = dec.ToString();

}
}

//buttom -


private void btMinus_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
return;
}
else
{
minus = true; //we make the 'minus' true
textBox1.Tag = textBox1.Text; // storage the number
textBox1.Text = ""; //clear the text box
}
}

//buttom multiply


private void btMult_Click(object sender, EventArgs e)
{
if (textBox1.Text == "") //if nothing is in the text box, we are going to returm
{
return;
}
else
{
multiply = true; //we make the 'multiply' true
textBox1.Tag = textBox1.Text; // storage the number
textBox1.Text = ""; //clear the text box
}
}

//buttom /


private void btDiv_Click(object sender, EventArgs e)
{
if (textBox1.Text == "") //if nothing is in the text box, we are going to returm
{
return;
}
else
{
divide = true; //we make the 'divide' true
textBox1.Tag = textBox1.Text; // storage the number
textBox1.Text = ""; //clear the text box
}
}

//buttom clear


private void btClear_Click(object sender, EventArgs e)
{
plus = minus = multiply = divide = false; //we make all the operations iqual false
textBox1.Text = ""; //make the screen clear
textBox1.Tag = ""; //Cleat the tag where the information is storage
}
Last edited on
Topic archived. No new replies allowed.