tsvetelinapasheva

ExcursionSale/Switch-case

Feb 28th, 2021
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp43
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int seaPacketNum = int.Parse(Console.ReadLine());
  10.             int mountainPacketNum = int.Parse(Console.ReadLine());
  11.             string destination = Console.ReadLine();
  12.             int profit = 0;
  13.             int seaPrice = 680;
  14.             int mountainPrice = 499;
  15.             string choice = " ";
  16.             while (destination != "Stop")
  17.             {
  18.                 choice = destination;
  19.                 switch (destination)
  20.                 {
  21.                     case "sea":
  22.                         if (seaPacketNum > 0)
  23.                         {
  24.                             seaPacketNum--;
  25.                             profit += seaPrice;
  26.  
  27.                         }
  28.                         break;
  29.                     case "mountain":
  30.                         if (mountainPacketNum > 0)
  31.                         {
  32.  
  33.                             mountainPacketNum--;
  34.                             profit += mountainPrice;
  35.                         }
  36.                         break;
  37.                 }
  38.  
  39.                 if (seaPacketNum == 0 && mountainPacketNum == 0)
  40.                 {
  41.                     break;
  42.                 }
  43.  
  44.                 destination = Console.ReadLine();
  45.             }
  46.             if (seaPacketNum == 0 && mountainPacketNum == 0)
  47.             {
  48.                 Console.WriteLine("Good job! Everything is sold.");
  49.             }
  50.  
  51.             Console.WriteLine($"Profit: {profit} leva.");
  52.  
  53.         }
  54.     }
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment