SvetlanPetrova

Basketball Tournament

Apr 6th, 2019 (edited)
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 KB | None | 0 0
  1. using System;
  2.  
  3. namespace BasketballTournament
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string tournamentName = string.Empty;
  10.             int matchesWin = 0;
  11.             int matchesLost = 0;
  12.             int matchNumber = 0;
  13.             int totalMatchNumber = 0;
  14.             double percentageWin = 0;
  15.             double percentageLost = 0;
  16.  
  17.             while (tournamentName != "End of tournaments")
  18.             {  
  19.                 tournamentName = Console.ReadLine();
  20.                 if (tournamentName == "End of tournaments")
  21.                 {
  22.                     break;
  23.                 }
  24.                 matchNumber = int.Parse(Console.ReadLine());
  25.                 totalMatchNumber += matchNumber;
  26.                 for (int i = 1; i <= matchNumber; i++)
  27.                 {    
  28.                     int ownPoints = int.Parse(Console.ReadLine());
  29.                     int oponentPoints = int.Parse(Console.ReadLine());
  30.  
  31.                    
  32.                     if (ownPoints > oponentPoints)
  33.                     {
  34.                         matchesWin++;
  35.                         Console.WriteLine($"Game {i} of tournament {tournamentName}: win with {ownPoints - oponentPoints} points.");
  36.                     }
  37.                     else if (ownPoints < oponentPoints)
  38.                     {
  39.                         matchesLost++;
  40.                         Console.WriteLine($"Game {i} of tournament {tournamentName}: lost with {oponentPoints - ownPoints} points.");
  41.                     }
  42.  
  43.                 }
  44.                 percentageWin = matchesWin * 100 * 1.0 / totalMatchNumber;
  45.                 percentageLost = matchesLost * 100 * 1.0 / totalMatchNumber;
  46.             }
  47.             Console.WriteLine($"{percentageWin:f2}% matches win");
  48.             Console.WriteLine($"{percentageLost:f2}% matches lost");
  49.         }
  50.     }
  51. }
Add Comment
Please, Sign In to add comment