silvana1303

easter eggs battle

May 2nd, 2020
653
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. using System;
  2.  
  3. namespace exampreparation
  4. {
  5.     class exam
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int playerOne = int.Parse(Console.ReadLine());
  10.             int playerTwo = int.Parse(Console.ReadLine());
  11.             string command = Console.ReadLine();
  12.  
  13.             while (command != "End of battle")
  14.             {
  15.                 if (command == "one")
  16.                 {
  17.                     playerTwo--;
  18.                 }
  19.                 else
  20.                 {
  21.                     playerOne--;
  22.                 }
  23.  
  24.                 if (playerOne == 0)
  25.                 {
  26.                     Console.WriteLine($"Player one is out of eggs. Player two has {playerTwo} eggs left.");
  27.                     break;
  28.                 }
  29.                 if (playerTwo == 0)
  30.                 {
  31.                     Console.WriteLine($"Player two is out of eggs. Player one has {playerOne} eggs left.");
  32.                     break;
  33.                 }
  34.  
  35.                 command = Console.ReadLine();
  36.             }
  37.  
  38.             if (command == "End of battle")
  39.             {
  40.                 Console.WriteLine($"Player one has {playerOne} eggs left.");
  41.                 Console.WriteLine($"Player two has {playerTwo} eggs left.");
  42.             }
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment