Facebook
From Ja, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 268
  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;
  18.             double oc, sr;
  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.                 if (oc == 2) ile2++;
  37.                 if (oc == 5) ile5++;
  38.                 }
  39.              
  40.                 sr = s / n;
  41.             Console.WriteLine("Średnia ocen to: {0}", sr);
  42.             Console.WriteLine(" Ilość dwójek to {0}, ilość piątek to {1}", ile2, ile5);
  43.              
  44.          
  45.             Console.ReadKey();
  46.             Console.WriteLine("Wciśnij dowolny klawisz");
  47.         }
  48.     }
  49. }
  50.