一个简单的成绩统计,求平均分跟最低分出错,不知道为什么
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace test1
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public int num = 1;
public double[] arr = new double[20];
public int element;
public MainWindow()
{
InitializeComponent();
textBox1.Text = "1";
}
private void button1_输入成绩_Click(object sender, RoutedEventArgs e)
{
element = 0;
arr[element] = Convert.ToDouble(textBox2.Text);
element++; num++;
textBox1.Text = Convert.ToString(num);
textBox2.Text = "";
}
private void button2_平均分_Click(object sender, RoutedEventArgs e)
{
double s = 0;
for (int i = 0; i < num - 1; i++)
s += arr[i];
textBox3.Text = Convert.ToString(s / (num - 1));
}
private void button4_最低分_Click(object sender, RoutedEventArgs e)
{
double low = 0;
for (int i = 0; i < num - 1; i++)
low = (arr[i] < low) ? arr[i] : low;
&n