2
I have a problem here and I need a help, I have to do a job for college, and a calculator, so far so good I’ve even made the calculator, only the problem and the next, I need to demonstrate the numbers in the pile, someone knows how to do it, by which I understood stack and last that goes in and first that comes out, only I have no idea how to do that in my code.
Follow the code of the calculator.
public partial class Form1 : Form
{
string operador;
int a = 0;
bool validar = false;
public Form1()
{
InitializeComponent();
}
private void btnNumerador_Click(object sender, EventArgs e)
{
Button bt = (Button)sender;
txt_valor.Text = txt_valor.Text + bt.Text;
}
private void btn_cancelar_Click(object sender, EventArgs e)
{
txt_valor.Text = "";
lbl_numero.Text = "";
a = 0;
}
private void btn_somar_Click(object sender, EventArgs e)
{
if (validar == true)
{
a = a + Convert.ToInt32(txt_valor.Text);
lbl_numero.Text = Convert.ToString(a) + "+";
txt_valor.Text = "";
operador = "+";
}
else
{
lbl_numero.Text = txt_valor.Text + btn_somar.Text;
a = Convert.ToInt32(txt_valor.Text);
txt_valor.Text = "";
operador = "+";
validar = true;
}
}
private void btn_subtrair_Click(object sender, EventArgs e)
{
if (validar == true)
{
a = a - Convert.ToInt32(txt_valor.Text);
lbl_numero.Text = Convert.ToString(a) + "-";
txt_valor.Text = "";
operador = "-";
validar = false;
}
else
{
lbl_numero.Text = txt_valor.Text + btn_subtrair.Text;
a = Convert.ToInt32(txt_valor.Text);
txt_valor.Text = "";
operador = "-";
}
}
private void btn_multiplicar_Click(object sender, EventArgs e)
{
if (validar == true)
{
a = a * Convert.ToInt32(txt_valor.Text);
lbl_numero.Text = Convert.ToString(a) + "*";
txt_valor.Text = "";
operador = "*";
}
else
{
lbl_numero.Text = txt_valor.Text + btn_multiplicar.Text;
a = Convert.ToInt32(txt_valor.Text);
txt_valor.Text = "";
operador = "*";
validar = true;
}
}
private void btn_dividir_Click(object sender, EventArgs e)
{
if (validar == true)
{
a = a / Convert.ToInt32(txt_valor.Text);
lbl_numero.Text = Convert.ToString(a) + "/";
txt_valor.Text = "";
operador = "/";
validar = false;
}
else
{
lbl_numero.Text = txt_valor.Text + btn_dividir.Text;
a = Convert.ToInt32(txt_valor.Text);
txt_valor.Text = "";
operador = "/";
}
}
private void btn_igual_Click(object sender, EventArgs e)
{
if (operador == "+")
{
lbl_numero.Text = lbl_numero.Text + txt_valor.Text + "=";
txt_valor.Text = Convert.ToString(a + Convert.ToInt32(txt_valor.Text));
}
else if (operador == "-")
{
lbl_numero.Text = lbl_numero.Text + txt_valor.Text + "=";
txt_valor.Text = Convert.ToString(a - Convert.ToInt32(txt_valor.Text));
}
else if (operador == "*")
{
lbl_numero.Text = lbl_numero.Text + txt_valor.Text + "=";
txt_valor.Text = Convert.ToString(a * Convert.ToInt32(txt_valor.Text));
}
else if (operador == "/")
{
lbl_numero.Text = lbl_numero.Text + txt_valor.Text + "=";
txt_valor.Text = Convert.ToString(a / Convert.ToInt32(txt_valor.Text));
}
}
}
}
"demonstrate the stack numbers" explain this statement better. Do you want to implement the calculations of a calculator based on a Stack-type data structure? display the result visually as if it were a stack ?
– Isac
That’s right Isac, I need to demonstrate the calculations as a pile structure base that’s right...
– Junior Guerreiro