Advertisement
IvetValcheva

08. Graduation

Mar 9th, 2024
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.51 KB | None | 0 0
  1.  
  2. string name = Console.ReadLine();
  3.  
  4. double sum = 0;
  5. int clas = 1;
  6. int failedTimes = 0;
  7.  
  8. while (clas <= 12)
  9. {
  10.     double grade = double.Parse(Console.ReadLine());
  11.  
  12.     if (grade >= 4)
  13.     {
  14.         clas++;
  15.         sum += grade;
  16.         continue;
  17.     }
  18.  
  19.     failedTimes++;
  20.  
  21.     if (failedTimes == 2)
  22.     {
  23.         Console.WriteLine($"{name} has been excluded at {clas} grade");
  24.         break;
  25.     }
  26. }
  27.  
  28. if (clas > 12)
  29. {
  30.     Console.WriteLine($"{name} graduated. Average grade: {sum/12:f2}");
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement