madeofglass

Untitled

Feb 19th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _04.Darts
  4. {
  5.     class Darts
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string name = Console.ReadLine();
  10.  
  11.  
  12.             int leftPoints = 301;
  13.             int removed = 0;
  14.             int counter = 0;
  15.             int failCounter = 0;
  16.  
  17.  
  18.             while (true)
  19.             {
  20.                 string field = Console.ReadLine();
  21.                 if(field == "Retire")
  22.                 {
  23.                     Console.WriteLine($"{name} retired after {failCounter} unsuccessful shots.");
  24.                     break;
  25.                 }
  26.                
  27.                 int points = int.Parse(Console.ReadLine());
  28.  
  29.                 if (field == "Single")
  30.                 {
  31.                     removed = points;
  32.                     counter++;
  33.                 }
  34.                 else if (field == "Double")
  35.                 {
  36.                     removed = (points * 2);
  37.                     counter++;
  38.                 }
  39.                 else if (field == "Triple")
  40.                 {
  41.                     removed = (points * 3);
  42.                     counter++;
  43.                 }
  44.  
  45.                 if (leftPoints < removed)
  46.                 {
  47.                     failCounter++;
  48.                     continue;
  49.                 }
  50.  
  51.                 if (leftPoints == removed)
  52.                 {
  53.                     Console.WriteLine($"{name} won the leg with {counter-failCounter} shots.");
  54.                     break;
  55.                 }
  56.  
  57.                 leftPoints = leftPoints - removed;
  58.             }
  59.         }
  60.     }
  61. }
Add Comment
Please, Sign In to add comment