Advertisement
silvana1303

darts

Apr 26th, 2020
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.07 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Loops
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string name = Console.ReadLine();
  10.             string command = Console.ReadLine();
  11.             int startPoints = 301;
  12.             int points = 0;
  13.             int success = 0;
  14.             int fail = 0;
  15.  
  16.             while (command != "Retire" && startPoints > 0)
  17.             {
  18.                 int gamePoints = int.Parse(Console.ReadLine());
  19.  
  20.                 if (command == "Triple")
  21.                 {
  22.                     points = gamePoints * 3;
  23.                     if (points <= startPoints)
  24.                     {
  25.                         startPoints -= points;
  26.                         success++;                        
  27.                     }
  28.                     else
  29.                     {
  30.                         fail++;
  31.                     }
  32.  
  33.                 }
  34.                 else if (command == "Double")
  35.                 {
  36.                     points = gamePoints * 2;
  37.                     if (points <= startPoints)
  38.                     {
  39.                         startPoints -= points;
  40.                         success++;
  41.                     }
  42.                     else
  43.                     {
  44.                         fail++;
  45.                     }
  46.  
  47.                 }
  48.                 else
  49.                 {
  50.                     points = gamePoints;
  51.                     if (points <= startPoints)
  52.                     {
  53.                         startPoints -= points;
  54.                         success++;
  55.                     }
  56.                     else
  57.                     {
  58.                         fail++;
  59.                     }
  60.  
  61.                 }
  62.  
  63.                 command = Console.ReadLine();              
  64.             }
  65.  
  66.             if (command == "Retire")
  67.             {
  68.                 Console.WriteLine($"{name} retired after {fail} unsuccessful shots.");
  69.             }
  70.  
  71.             if (startPoints == 0 )
  72.             {
  73.                 Console.WriteLine($"{name} won the leg with {success} shots.");
  74.             }
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement