using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Microsoft.Phone.Controls; namespace Licznik { public partial class MainPage : PhoneApplicationPage { List Lista_liczb; // Constructor public MainPage() { InitializeComponent(); Lista_liczb = new List(); } int ilosc = 0; double suma = 0; private void button1_Click(object sender, RoutedEventArgs e) { //suma += Convert.ToInt32(textBox1.Text); //ilosc++; //textBlock2.Text = Convert.ToString((suma / ilosc)); //textBox1.Text = ""; Lista_liczb.Add(Convert.ToDouble(textBox1.Text)); } private void textBox1_GotFocus(object sender, RoutedEventArgs e) { textBox1.Text = ""; } private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e) { var wybrany = (ListBoxItem)e.AddedItems[0]; if ((string)wybrany.Content == "średnia arytmetyczna") { suma = 0; foreach (var liczba in Lista_liczb) { suma += liczba; ilosc++; } textBlock2.Text = Convert.ToString((suma / ilosc)); } else if ((string)wybrany.Content == "średnia geometryczna") { suma = 1; foreach (var liczba in Lista_liczb) { suma = suma*liczba; ilosc++; } double potega = 1 / (double)ilosc; double wynik=Math.Pow(suma,potega); textBlock2.Text = Convert.ToString(wynik); } else if ((string)wybrany.Content == "średnia harmoniczna") { suma = 0; foreach (var liczba in Lista_liczb) { suma += 1/liczba; ilosc++; } double wynik=ilosc/suma; textBlock2.Text = Convert.ToString(wynik); } } private void button3_Click(object sender, RoutedEventArgs e) { Lista_liczb.Clear(); textBlock2.Text = ""; } } }