ralichka

05.More.Exercises.For.Loop-04.Grades

Jul 12th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.74 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Grades
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int students = int.Parse(Console.ReadLine());
  10.  
  11.             double p1 = 0;
  12.             double p2 = 0;
  13.             double p3 = 0;
  14.             double p4 = 0;
  15.            
  16.             double p1Percent = 0;
  17.             double p2Percent = 0;
  18.             double p3Percent = 0;
  19.             double p4Percent = 0;
  20.  
  21.             double totalGrade = 0;
  22.  
  23.             for (int i = 0; i < students; i++)
  24.             {
  25.                 double grade = double.Parse(Console.ReadLine());
  26.  
  27.                 if (grade < 3)
  28.                 {
  29.                     p1++;
  30.                    
  31.                 }
  32.                 else if (grade < 4)
  33.                 {
  34.                     p2++;
  35.                    
  36.                 }
  37.                 else if (grade < 5)
  38.                 {
  39.                     p3++;
  40.                    
  41.                 }
  42.                 else
  43.                 {
  44.                     p4++;
  45.                    
  46.                 }
  47.                 totalGrade+= grade;
  48.  
  49.                 p1Percent = p1 / students * 100;
  50.                 p2Percent = p2 / students * 100;
  51.                 p3Percent = p3 / students * 100;
  52.                 p4Percent = p4 / students * 100;
  53.             }
  54.  
  55.             double average = 0;
  56.             average = totalGrade / students;
  57.  
  58.             Console.WriteLine($"Top students: {p4Percent:f2}%");
  59.             Console.WriteLine($"Between 4.00 and 4.99: {p3Percent:f2}%");
  60.             Console.WriteLine($"Between 3.00 and 3.99: {p2Percent:f2}% ");
  61.             Console.WriteLine($"Fail: { p1Percent:f2}%");
  62.             Console.WriteLine($"Average: {average:f2}");
  63.  
  64.  
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment