using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Program { class Program { static void Main(string[] args) { Console.WriteLine("Program liczy średnią ocene"); int n, ile2 = 0, ile5 = 0, j = 0; double oc, sr, sk = 0, s2=0, war; Console.WriteLine("Wpisz ile ocen:"); while (!int.TryParse(Console.ReadLine(), out n) && n < 1) Console.WriteLine("Błędna wartość podaj jeszcze raz:"); double s = 0; Console.WriteLine("Podaj ilość ocen ucznia?"); for (int i = 1; i <= n; i++) { Console.Write("{0}:Ocena", i); while (!double.TryParse(Console.ReadLine(), out oc) || //oc < 2 || oc > 5) // /* jest źle*/ (oc !=2 && oc !=3 && oc !=3.5 && oc !=4 && oc !=4.5 && oc !=5) /*jest dobrze*/ !(oc == 2 || oc == 3 || oc == 3.5 || oc == 4 || oc == 4.5 || oc ==5) ) Console.WriteLine("Błędna wartość, podaj jeszcze raz: "); s = s + oc; s2 = (oc * oc)+s2; if (oc == 2) ile2++; if (oc == 5) ile5++; if (oc != 5 && oc != 2) sk = oc + sk; j++; } sr = s / n; war = (s2 / n) - (sr * sr); Console.WriteLine("Średnia ocen to: {0}, a wariancja= {1}", sr, war); Console.WriteLine(" Ilość dwójek to {0}, ilość piątek to {1}", ile2, ile5); if (j != 0) Console.WriteLine("Średnia srednich to: {0}", sk/j); Console.WriteLine("Wciśnij dowolny klawisz"); Console.ReadKey(); } } }