bacco

Оценки : Grades ; Loops

Feb 1st, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.45 KB | None | 0 0
  1. using System;
  2.  
  3. namespace tESt
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.  
  9.         {
  10.             var studentsNumber = double.Parse(Console.ReadLine());  //  students number
  11.  
  12.             double scoreTop = 0;      // Top
  13.             double scoreGood = 0;     // Good
  14.             double scoreMidle = 0;    // Middle
  15.             double scoreFail = 0;     // Fail
  16.  
  17.             double allStudents = 0;
  18.  
  19.             double topStudents = 0;      // Top    numbers  
  20.             double goodStudents = 0;     // Good   numbers
  21.             double midleStudents = 0;    // Middle numbers
  22.             double failStudents = 0;     // Fail   numbers
  23.  
  24.  
  25.             for (int i = 0; i < studentsNumber; i++)
  26.             {
  27.                 var num = double.Parse(Console.ReadLine());
  28.  
  29.                 allStudents = allStudents + 1;
  30.  
  31.  
  32.                 if (num >= 5.00)        // Top
  33.                 {
  34.                     scoreTop = scoreTop + num;
  35.                     topStudents = topStudents + 1;
  36.                 }
  37.                 else if (num >= 4.00)   // Good
  38.                 {
  39.                     scoreGood = scoreGood + num;
  40.                     goodStudents = goodStudents + 1;
  41.                 }
  42.                 else if (num >= 3.00)   // Middle
  43.                 {
  44.                     scoreMidle = scoreMidle + num;
  45.                     midleStudents = midleStudents + 1;
  46.                 }
  47.                 else if (num < 3.00)    // Fail  
  48.                 {
  49.                     scoreFail = scoreFail + num;
  50.                     failStudents = failStudents + 1;
  51.                 }
  52.             }
  53.  
  54.             var topPorcent = (topStudents / allStudents) * 100.0;     // Top    % (Porcentage)
  55.             var goodPorcent = (goodStudents / allStudents) * 100.0;   // Good   % (Porcentage)
  56.             var midlePorcent = (midleStudents / allStudents) * 100.0; // Middle % (Porcentage)
  57.             var failPorcent = (failStudents / allStudents) * 100.0;   // Fail   % (Porcentage)
  58.  
  59.             var ScrowAll = (scoreTop + scoreGood + scoreMidle + scoreFail) / allStudents;
  60.  
  61.             Console.WriteLine($"Top students: {topPorcent:f2}%");
  62.             Console.WriteLine($"Between 4.00 and 4.99: {goodPorcent:f2}%");
  63.             Console.WriteLine($"Between 3.00 and 3.99: {midlePorcent:f2}%");
  64.             Console.WriteLine($"Fail: {failPorcent:f2}%");
  65.  
  66.             Console.WriteLine( $"Average: {ScrowAll:f2}");
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment