codigo roda normal, o problema e que na hora de apresentar o valor de x1 e x2 aparece ‘NaN’ | ‘NaN’
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace teste3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void label4_Click(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void btnCalcular_Click(object sender, EventArgs e)
{
double a, b, c, x1, x2;
a = Convert.ToDouble(txtA.Text);
b = Convert.ToDouble(txtB.Text);
c = Convert.ToDouble(txtC.Text);
double delta1 = Math.Sqrt(b * b);
double delta2 = Math.Sqrt(4 * a * c);
double delta = (delta1 - delta2);
double raiz = Math.Sqrt(delta);
x1 = ((-(b)) + raiz) / (2 * a);
x2 = ((-(b)) - raiz) / (2 * a);
if(a != 0 |delta > 0)
{
txtX1.Text = x1.ToString();
txtX2.Text = x2.ToString();
}
else
{
MessageBox.Show("Impossivel calcular", "Verifique", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
}