martes, 17 de noviembre de 2009

Practica extra problema 1 visual


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 practica_extra_suma_de_nuemeros_visual
{
public partial class Form1 : Form
{
int n, suma, promedio, dato;
public Form1()
{
InitializeComponent();
n = suma = promedio = 0;
dato = 0;
label1.Text= "introduceun numero entero".ToString();
}

private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Add("numero entero");
n = int.Parse(textBox1.Text);
listBox1.Items.Add(n.ToString());
if (n != 9999)
{
suma = suma + n;
textBox1.Clear();
textBox1.Focus();
dato++;
if (n == 9999)
{
textBox1.Clear();
textBox1.Enabled = false;
button1.Enabled = false;
}



}
else
{
textBox1.Clear();
textBox1.Enabled = false;
button1.Enabled = false;
if (n == 0)
{
label1.Text = "introduceun numero diferente a 0".ToString();
}

}
}

private void button2_Click(object sender, EventArgs e)
{
promedio = suma / dato;
listBox1.Items.Add("el promedio es "+promedio.ToString());

}

private void button3_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
textBox1.Enabled = true;
button1.Enabled = true;
}

private void button4_Click(object sender, EventArgs e)
{
Close();
}
}
}

No hay comentarios:

Publicar un comentario