Advertisement
Spocoman

02. Exam Preparation

Nov 21st, 2021 (edited)
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ExamPreparation
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int badGrades = int.Parse(Console.ReadLine());
  10.             string task = Console.ReadLine();
  11.  
  12.             int badGradesCounter = 0;
  13.             double gradesTotal = 0;
  14.             double tasksCount = 0;
  15.             string lastProblem = "";
  16.  
  17.             while (task != "Enough")
  18.             {
  19.                 double grade = double.Parse(Console.ReadLine());
  20.                 gradesTotal += grade;
  21.                 tasksCount++;
  22.  
  23.                 if (grade <= 4)
  24.                 {
  25.                     badGradesCounter++;
  26.  
  27.                     if (badGradesCounter == badGrades)
  28.                     {
  29.                         Console.WriteLine($"You need a break, {badGradesCounter} poor grades.");
  30.                         break;
  31.                     }
  32.                 }
  33.                 lastProblem = task;
  34.                 task = Console.ReadLine();
  35.             }
  36.  
  37.             if (task == "Enough")
  38.             {
  39.                 Console.WriteLine($"Average score: {gradesTotal / tasksCount:F2}");
  40.                 Console.WriteLine($"Number of problems: {tasksCount}");
  41.                 Console.WriteLine($"Last problem: {lastProblem}");
  42.             }
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement