从文本框输入任意几个数字,然后计算出最高分 最低分 去掉最高分和最低分求出平均分
[AppleScript] 纯文本查看 复制代码 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 Mark
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int count = 0;
private void button1_Click(object sender, EventArgs e)
{
if (txtScore.Text == "")
{
MessageBox.Show("请输入分数!");
}
else
{
lvScore.Items.Add(txtScore.Text.Trim());
txtScore.Text = "";
count++;
}
}
private void btnClear_Click(object sender, EventArgs e)
{
lvScore.Items.Clear();
}
private void btnCaculate_Click(object sender, EventArgs e)
{
double sum=0,max,min,average;
for (int i = 0; i < count; i++)
{
sum += Convert.ToDouble(lvScore.Items[i]);
max = Math.Max(Convert.ToDouble(lvScore.Items[0]), Convert.ToDouble(lvScore.Items[i]));
min = Math.Min(Convert.ToDouble(lvScore.Items[0]), Convert.ToDouble(lvScore.Items[i]));
average = (sum - max - min) / (count - 2);
lblResult.Text = "最大数:" + max.ToString() + "\n" + "最小数:" + min.ToString() + "\n" + "平均数:" + average.ToString();
}
}
private void txtScore_KeyPress(object sender, KeyPressEventArgs e)
{
TextBox currentTextBox = sender as TextBox;
if (e.KeyChar < '0' || e.KeyChar > '9') //不是数字
{
e.Handled = true;
}
if (e.KeyChar == 8)
{
e.Handled = false;
}
if (e.KeyChar == 46)
{
if (currentTextBox.Text.IndexOf(".") == -1)
{
if (currentTextBox.SelectionStart > 0)
{
e.Handled = false;
}
}
}
}
}
}
这是我的代码
求大神一定要帮忙看看啊
|