Advertisement
IvetValcheva

Exam Preparation

Oct 9th, 2022
1,427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.93 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Exam_Preparation
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             //1. Четем от конзолата брой незадоволителни оценки, при които трябва да прекъсне
  10.             int filedTimes = int.Parse(Console.ReadLine());
  11.  
  12.             // променлива за: сума на вс. оценки;
  13.             int evaluationSum = 0;
  14.             // променлива за:  брой оценки;
  15.             int evaluationCount = 0;
  16.             // променлива за:  брой незадоволителни оценки, които е получил
  17.             int filedCount = 0;
  18.  
  19.             // променлива за:  име на текущата задача
  20.             string lastExercise = string.Empty;
  21.             // променлива за:  текуща оценка
  22.             int evaluation;
  23.  
  24.             string input = Console.ReadLine();
  25.  
  26.             //2. Създаваме цикъл, който да се изпълнява, докато не получим "Enough"
  27.             while (input!= "Enough")
  28.             {
  29.                 // => присвояваме име на задача
  30.                 lastExercise = input;
  31.                 // => четем оценка, която е получил
  32.                 evaluation = int.Parse(Console.ReadLine());
  33.  
  34.                 // увеличаваме броя на всички оценки с 1
  35.                 evaluationCount++;
  36.                 // добавяме оценката към сумата на всички оценки
  37.                 evaluationSum += evaluation;
  38.  
  39.                 // => проверяваме дали оценката е >4
  40.                 if (evaluation<=4)
  41.                 {
  42.                     // увеличаваме броя незадоволителни оценки, които е получил с 1
  43.                     filedCount++;
  44.  
  45.                     // => проверяваме дали стигнал броя на оценките, при който трябва да си вземе почивка
  46.                     if(filedCount == filedTimes)
  47.                     {
  48.                         Console.WriteLine($"You need a break, {filedCount} poor grades.");
  49.                         break;
  50.                     }
  51.                 }
  52.  
  53.                 //четем нов вход от конзолата
  54.                 input = Console.ReadLine();
  55.             }
  56.  
  57.  
  58.             //3. Ако последният вход от конзолата == "Enough"
  59.             if(input== "Enough")
  60.             {
  61.                 Console.WriteLine($"Average score: {(double)evaluationSum/evaluationCount:f2}");
  62.                 Console.WriteLine($"Number of problems: {evaluationCount}");
  63.                 Console.WriteLine($"Last problem: {lastExercise}");
  64.             }
  65.         }
  66.     }
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement