sanyakasarova

Graduation

Feb 5th, 2022 (edited)
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Loops
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9.  
  10. string name = Console.ReadLine();
  11.  
  12. int grade = 1; // the current grade of the student, e.g 1
  13. double sum = 0;
  14. int counter = 0; // counts the number of times the student has been excluded
  15.  
  16. while (grade <= 12)
  17. {
  18. double yearlyGrade = double.Parse(Console.ReadLine()); // the yearly grade of the student, e.g 5.60
  19.  
  20. if (yearlyGrade < 4)
  21. {
  22. counter++;
  23. if (counter == 2)
  24. {
  25. break;
  26. }
  27.  
  28. continue;
  29. }
  30.  
  31. sum += yearlyGrade;
  32.  
  33. grade++;
  34. }
  35.  
  36.  
  37. double averageGrade = sum / 12;
  38.  
  39. if (grade > 12)
  40. {
  41. Console.WriteLine($"{name} graduated. Average grade: {averageGrade:f2}");
  42. }
  43. else
  44. {
  45. Console.WriteLine($"{name} has been excluded at {grade} grade");
  46. }
  47.  
  48. }
  49. }
  50. }
  51.  
Add Comment
Please, Sign In to add comment