Facebook
From Ja, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 213
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Program
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             Console.WriteLine("Program liczy średnią ocene");
  15.  
  16.  
  17.             int n, ile2 = 0, ile5 = 0, j = 0;
  18.             double oc, sr, sk = 0, s2=0, war;
  19.  
  20.             Console.WriteLine("Wpisz ile ocen:");
  21.             while (!int.TryParse(Console.ReadLine(), out n) && n < 1)
  22.                 Console.WriteLine("Błędna wartość podaj jeszcze raz:");
  23.  
  24.             double s = 0;
  25.             Console.WriteLine("Podaj ilość ocen ucznia?");
  26.             for (int i = 1; i <= n; i++)
  27.             {
  28.                 Console.Write("{0}:Ocena", i);
  29.                 while (!double.TryParse(Console.ReadLine(), out oc) ||
  30.                     //oc < 2 || oc > 5)
  31.                     // /* jest źle*/  (oc !=2 && oc !=3 && oc !=3.5 && oc !=4 && oc !=4.5 && oc !=5)
  32.                     /*jest dobrze*/ !(oc == 2 || oc == 3 || oc == 3.5 || oc == 4 || oc == 4.5 || oc ==5)
  33.                         )
  34.                         Console.WriteLine("Błędna wartość, podaj jeszcze raz: ");
  35.                     s = s + oc;
  36.                 s2 = (oc * oc)+s2;
  37.                 if (oc == 2) ile2++;
  38.                 if (oc == 5) ile5++;
  39.                 if (oc != 5 && oc != 2)
  40.                    sk = oc + sk;
  41.                 j++;
  42.  
  43.                 }
  44.             sr = s / n;
  45.             war = (s2 / n) - (sr * sr);
  46.  
  47.                    
  48.             Console.WriteLine("Średnia ocen to: {0}, a wariancja= {1}", sr, war);
  49.             Console.WriteLine(" Ilość dwójek to {0}, ilość piątek to {1}", ile2, ile5);
  50.             if (j != 0)
  51.             Console.WriteLine("Średnia srednich to: {0}", sk/j);
  52.             Console.WriteLine("Wciśnij dowolny klawisz");
  53.             Console.ReadKey();
  54.            
  55.         }
  56.     }
  57. }
  58.