calculadora
Publicado por elruffo (9 intervenciones) el 23/07/2010 04:40:49
Buenas amigos, estoy teniendo un pequeño problema es que cuando estoy utilizando un declaracion switch en el boton igual (btnIgual) no me esta respondiendo ninguna de las opciones para realizar el calculo esperando una ayuda de ustedes ya que soy novato en estoi gracias ....
elruffo
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace calculadora
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
double total1 = 0;
double total2 = 0;
string operador;
private void btnUno_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnUno.Text;
}
private void btnDos_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnDos.Text;
}
private void btnTres_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnTres.Text;
}
private void btnCuatro_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnCuatro.Text;
}
private void btnCinco_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnCinco.Text;
}
private void btn6_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnSeis.Text;
}
private void btn7_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnSiete.Text;
}
private void btnOcho_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnOcho.Text;
}
private void btnNueve_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnNueve.Text;
}
private void btnCero_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnCero.Text;
}
private void btnPunto_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnPunto.Text;
}
private void button3_Click(object sender, EventArgs e)
{
txtDisplay.Clear();
}
private void btnSuma_Click(object sender, EventArgs e)
{
total1 += double.Parse(txtDisplay.Text);
txtDisplay.Clear();
operador ="+";
}
private void btnIgual_Click(object sender, EventArgs e)
{
switch (operador)
{
case "+":
total2 = total1 + double.Parse(txtDisplay.Text);
break;
case "-":
total2 = total1 - double.Parse(txtDisplay.Text);
break;
case "*":
total2 = total1 * double.Parse(txtDisplay.Text);
break;
case "/":
total2 = double.Parse(txtDisplay.Text);
break;
default:
MessageBox.Show("El (=) debe último click");
break;
}
}
private void btnCerrar_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btnmenos_Click(object sender, EventArgs e)
{
total1 += double.Parse(txtDisplay.Text);
txtDisplay.Clear();
operador ="-";
}
private void btnmultip_Click(object sender, EventArgs e)
{
total1 = total1 + double.Parse(txtDisplay.Text);
txtDisplay.Clear();
operador ="*";
}
private void btndivid_Click(object sender, EventArgs e)
{
total1 += double.Parse(txtDisplay.Text);
txtDisplay.Clear();
operador ="/";
}
}
}
elruffo
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace calculadora
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
double total1 = 0;
double total2 = 0;
string operador;
private void btnUno_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnUno.Text;
}
private void btnDos_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnDos.Text;
}
private void btnTres_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnTres.Text;
}
private void btnCuatro_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnCuatro.Text;
}
private void btnCinco_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnCinco.Text;
}
private void btn6_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnSeis.Text;
}
private void btn7_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnSiete.Text;
}
private void btnOcho_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnOcho.Text;
}
private void btnNueve_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnNueve.Text;
}
private void btnCero_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnCero.Text;
}
private void btnPunto_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnPunto.Text;
}
private void button3_Click(object sender, EventArgs e)
{
txtDisplay.Clear();
}
private void btnSuma_Click(object sender, EventArgs e)
{
total1 += double.Parse(txtDisplay.Text);
txtDisplay.Clear();
operador ="+";
}
private void btnIgual_Click(object sender, EventArgs e)
{
switch (operador)
{
case "+":
total2 = total1 + double.Parse(txtDisplay.Text);
break;
case "-":
total2 = total1 - double.Parse(txtDisplay.Text);
break;
case "*":
total2 = total1 * double.Parse(txtDisplay.Text);
break;
case "/":
total2 = double.Parse(txtDisplay.Text);
break;
default:
MessageBox.Show("El (=) debe último click");
break;
}
}
private void btnCerrar_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btnmenos_Click(object sender, EventArgs e)
{
total1 += double.Parse(txtDisplay.Text);
txtDisplay.Clear();
operador ="-";
}
private void btnmultip_Click(object sender, EventArgs e)
{
total1 = total1 + double.Parse(txtDisplay.Text);
txtDisplay.Clear();
operador ="*";
}
private void btndivid_Click(object sender, EventArgs e)
{
total1 += double.Parse(txtDisplay.Text);
txtDisplay.Clear();
operador ="/";
}
}
}
Valora esta pregunta


0