#define daneTestowe 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) { int n, ile2 = 0, ile5 = 0, j = 0, iluGorszych = 0; double sr, sk = 0, suma2 = 0, war; string[] tabNazwisk; double[] tabOcen; Console.WriteLine("Program liczy średnią ocen"); //dane testowe #if (daneTestowe) tabOcen = new double[] { 2.0, 4.5, 5.0, 2.0, 3.5, 4.5, 2.0, 4.0, 5.0, 3.0 }; tabNazwisk = new string[] { "Stachowiak", "Kot", "Kabat", "Dolata", "Krajewska", "Pawłowska", "Lis", "Krawczyk", "Nowak", "Berkut" }; n = tabNazwisk.Length; if (n != tabOcen.Length) Console.WriteLine("źle!"); #endif //dane testowe //dane z konsoli #if (!daneTestowe) Console.WriteLine("Wpisz ile uczniów:"); while (!int.TryParse(Console.ReadLine(), out n) && n < 1) Console.WriteLine("Błędna wartość podaj jeszcze raz:"); tabOcen = new double[n]; tabNazwisk= new string[n]; #endif double suma = 0; #region for (int i = 1; i <= n; i++) { //dane z konsoli #if (!daneTestowe) Console.Write("Podaj nazwisko: "); tabNazwisk[i - 1] = Console.ReadLine(); Console.WriteLine("Podaj ocene ucznia"); double oc; Console.Write("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: "); tabOcen[i - 1] = oc; #endif //dane testowe #if (daneTestowe) double oc= tabOcen[i - 1]; #endif //koniec suma = suma + oc; suma2 = (oc * oc)+suma2; if (oc == 2) ile2++; if (oc == 5) ile5++; if (oc != 5 && oc != 2) sk = oc + sk; j++; } #endregion sr = suma / n; foreach(var oc in tabOcen) if (oc < sr) iluGorszych++; war = (suma2 / n) - (sr * sr); Console.WriteLine("Średnia ocen to: {0}, a wariancja= {1:F1}", sr, war); Console.WriteLine(" Ilość dwójek to {0}, ilość piątek to {1}, a ocen poniżej średniej: {2}", ile2, ile5, iluGorszych); if (j != 0) Console.WriteLine("Średnia srednich to: {0:F2}", sk/j); Console.WriteLine("\n *** Lista z oceniami ndst *** "); for (int i = 0; i < n; i++) if (tabOcen[i]==2) Console.WriteLine(" nazwisko: {0} ocena: {1} ", tabNazwisk[i], tabOcen[i]); Console.WriteLine("\n *** Lista z oceniami bdb *** "); for (int i = 0; i < n; i++) if (tabOcen[i] == 5) Console.WriteLine(" nazwisko: {0} ocena: {1} ", tabNazwisk[i], tabOcen[i]); Console.WriteLine("\n *** Lista z oceniami poniżej sredniej *** "); for (int i = 0; i < n; i++) if (tabOcen[i] < sr) Console.WriteLine(" nazwisko: {0} ocena: {1} ", tabNazwisk[i], tabOcen[i]); Console.WriteLine("Wciśnij dowolny klawisz..."); Console.ReadKey(); } } }