Código:
butRaiz_Click
, arroja el error: La cadena de entrada no tiene el formato correcto. aca esta el codigo:Código
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Proyectogestor
{
public partial class Form1 : Form
{
//Variables globales...
float num1;
string op;
public Form1()
{
InitializeComponent();
}
//Boton igual...
private void butIgual_Click(object sender, EventArgs e)
{
float num2;
try
{
num2 = float.Parse(textVisor.Text);
switch (op)
{
case "sumar":
textVisor.Text = "" + suma(num1, num2);
break;
case "restar":
textVisor.Text = "" + resta(num1, num2);
break;
case "multiplicar":
textVisor.Text = "" + multi(num1, num2);
break;
case "dividir":
textVisor.Text = "" + divi(num1, num2);
break;
case "potenciar":
textVisor.Text = "" + Math.Pow(num1,num2);
break;
case "raiz":
textVisor.Text = "" + Math.Sqrt(num1);
break;
}
}
catch (Exception aviso)
{
MessageBox.Show(aviso.Message, "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Information);
throw;
}
}
//Metodos de las operaciones...
public float suma(float num3, float num4)
{
try
{
return (num3 + num4);
}
catch (Exception ex1)
{
MessageBox.Show(ex1.Message, "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Information);
throw;
}
}
public float resta(float num3, float num4)
{
try
{
return (num3 - num4);
}
catch (Exception ex1)
{
MessageBox.Show(ex1.Message, "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Information);
throw;
}
}
public float multi(float num3, float num4)
{
try
{
return (num3 * num4);
}
catch (Exception ex1)
{
MessageBox.Show(ex1.Message, "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Information);
throw;
}
}
public float divi(float num3, float num4)
{
try
{
return (num3 / num4);
}
catch (Exception ex1)
{
MessageBox.Show(ex1.Message, "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Information);
throw;
}
}
//Numeros...
private void but0_Click(object sender, EventArgs e)
{
textVisor.Text = textVisor.Text + "0";
}
private void butComa_Click(object sender, EventArgs e)
{
textVisor.Text = textVisor.Text + ",";
butComa.Enabled = false;
}
private void but1_Click(object sender, EventArgs e)
{
textVisor.Text = textVisor.Text + "1";
}
private void but2_Click(object sender, EventArgs e)
{
textVisor.Text = textVisor.Text + "2";
}
private void but3_Click(object sender, EventArgs e)
{
textVisor.Text = textVisor.Text + "3";
}
private void but4_Click(object sender, EventArgs e)
{
textVisor.Text = textVisor.Text + "4";
}
private void but5_Click(object sender, EventArgs e)
{
textVisor.Text = textVisor.Text + "5";
}
private void but6_Click(object sender, EventArgs e)
{
textVisor.Text = textVisor.Text + "6";
}
private void but7_Click(object sender, EventArgs e)
{
textVisor.Text = textVisor.Text + "7";
}
private void but8_Click(object sender, EventArgs e)
{
textVisor.Text = textVisor.Text + "8";
}
private void but9_Click(object sender, EventArgs e)
{
textVisor.Text = textVisor.Text + "9";
}
//Botones adicionales...
private void butSalir_Click(object sender, EventArgs e)
{
Close();
}
private void butLimpiar_Click(object sender, EventArgs e)
{
textVisor.Text = "";
}
//Botones de operaciones...
private void butMas_Click(object sender, EventArgs e)
{
butComa.Enabled = true;
try
{
num1 = float.Parse(textVisor.Text);
}
catch (Exception aviso)
{
MessageBox.Show(aviso.Message, "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Information);
throw;
}
textVisor.Text = "";
op = "sumar";
}
private void butMenos_Click(object sender, EventArgs e)
{
butComa.Enabled = true;
try
{
num1 = float.Parse(textVisor.Text);
}
catch (Exception aviso)
{
MessageBox.Show(aviso.Message, "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Information);
throw;
}
textVisor.Text = "";
op = "restar";
}
private void butPor_Click(object sender, EventArgs e)
{
butComa.Enabled = true;
try
{
num1 = float.Parse(textVisor.Text);
}
catch (Exception aviso)
{
MessageBox.Show(aviso.Message, "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Information);
throw;
}
textVisor.Text = "";
op = "multiplicar";
}
private void butDivis_Click(object sender, EventArgs e)
{
butComa.Enabled = true;
try
{
num1 = float.Parse(textVisor.Text);
}
catch (Exception aviso)
{
MessageBox.Show(aviso.Message, "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Information);
throw;
}
textVisor.Text = "";
op = "dividir";
}
private void butPot_Click(object sender, EventArgs e)
{
butComa.Enabled = true;
try
{
num1 = float.Parse(textVisor.Text);
}
catch (Exception aviso)
{
MessageBox.Show(aviso.Message, "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Information);
throw;
}
textVisor.Text = "";
op = "potenciar";
}
private void butRaiz_Click(object sender, EventArgs e)
{
butComa.Enabled = true;
try
{
num1 = float.Parse(textVisor.Text);
}
catch (Exception aviso)
{
MessageBox.Show(aviso.Message, "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Information);
throw;
}
textVisor.Text = "";
op = "raiz";
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}










Autor


En línea


nada mas me falta lo demas

