Red de conocimiento informático - Computadora portátil - Cómo escribir sumas y restas aleatorias simples en C#

Cómo escribir sumas y restas aleatorias simples en C#

¿Está bien?

Desde Internet.

El siguiente es el código fuente

Usar System

Usar System.Collections.Generic

Usar System.ComponentModel <; /p >

Usar System.Data;

Usar System.Drawing;

Usar System.Text;

Usar System.Windows.Forms;

espacio de nombres Aplicación de Windows;

Espacio de nombres Aplicación de Windows.

Formularios;

espacio de nombres WindowsApplication1

{

clase parcial pública Principal: Formulario

{

público Principal()

{

InitializeComponent();

}

private void Main_Load( remitente del objeto, EventArgs e)

{

}

private void txtInshu1_TextChanged(objeto remitente,

}

private void txtInshu1_TextChanged(objeto remitente, EventArgs e)

{

OnlyEnterNumber(remitente, e);

}

//// resumen

// / Ingrese solo números (números negativos con punto decimal)

/// lt;/summarygt;

/// lt;param name="sender"gt;lt;/paramgt ;

/// lt;param name="e"gt;lt;/paramgt;

public static void OnlyEnterNumber(remitente del objeto, KeyPressEventArgs e)

{

if ((e. KeyChar lt; lt; /paramgt;

)KeyChar lt; | e.KeyChar lt; | e.KeyChar lt; | e.KeyChar lt ; | e.KeyChar lt; | e.KeyChar ! KeyChar = 46)

{

e.processing = true

}

// Cuando la entrada es un número negativo , solo se puede ingresar una vez y solo una vez

if (e.KeyChar == 45 amp; amp; (((TextBox)sender).SelectionStart ! = 0 || ((TextBox)sender). Text.IndexOf("-") gt; = 0)) e.Handled = true

if (e.KeyChar == 46 amp; amp; ((TextBox) remitente).Text.IndexOf( ".") gt; = 0) e.Handled = true;

}

/*

?* Parámetros: d representa el número a redondear; i representa el número de decimales a retener.

?* Los números positivos y negativos se redondearán, lo que es adecuado para mostrar datos estadísticos

?*/

double Round(double d, int i)

{

if (d gt; = 0)

{

d = 5 * Math.Pow(10, -(i 1 ));

}

else

{

d = -5 * Math.Pow(10, -(i 1)

}

cadena str = d.ToString();

cadena[] cadena = str.Split('.') ; >

int idot = str.IndexOf('.');

string prestr = strs[0]

string poststr = strs[1];

if (poststr.Length gt; i)

{

poststr = str.Substring(idot 1, i);

}

cadena strd = prestr ". poststr;

d = Double.Parse(strd);

return d;

}

private void txtInshu2_TextChanged(objeto remitente, EventArgs e)

{

}

private void txtInshu2_KeyPress_1(objeto remitente, KeyPressEventArgs e)

{

OnlyEnterNumber(remitente, e);

}

private void btnJisuan_Click(objeto remitente, EventArgs e)

{

if (txtInshu1.Text == "") {

MessageBox.Show("¡Factor1 no puede ser nulo!", "Advertencia", "MessageBox.Show("Factor1 no puede ser nulo!" ser nulo!" ), "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning);

Retorno;

}

If (txtInshu2.Text == "")

{

MessageBox.Show("¡El factor 2 no puede ser nulo!") {

Retorno.

Show("¡El factor 2 no puede ser nulo!", "Advertencia", MessageBox., "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning

Retorno

}

doble inshu1 = Convert.ToDouble(txtInshu1.Text);

doble inshu2 = Convert.ToDouble(txtInshu2.Text);

Retorno. Texto);

resultado doble = 0.0;

if (radioBtnJia.Checked) {

resultado = inshu1 inshu2

}

if (radioBtnJian.Checked)

{

resultado = inshu1 - inshu2

}

if ( radioBtnCheng.Checked)

{

resultado = inshu1 - inshu2

}

if (radioBtnCheng.Checked)