Advertisement
Spocoman

09. Ski Trip(with ternary operator)

Nov 19th, 2021 (edited)
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. using System;
  2.  
  3. namespace SkiTrip
  4. {
  5.     class Program
  6.     {
  7.         static void Main()
  8.         {
  9.             int night = int.Parse(Console.ReadLine()) - 1;
  10.             string room = Console.ReadLine();
  11.             string rating = Console.ReadLine();
  12.             double price = night;
  13.  
  14.             _ = room == "room for one person" ? price *= 18
  15.                : room == "apartment" ? price *= 25 : price *= 35;
  16.  
  17.             _ = room == "apartment" && night < 10 ? price *= 0.7
  18.                 : room == "apartment" && night >= 15 ? price /= 2
  19.                 : room == "apartment" ? price *= 0.65 : price;
  20.            
  21.             _ = room == "president apartment" && night < 10 ? price *= 0.9
  22.                 : room == "president apartment" && night >= 15 ? price *= 0.8
  23.                 : room == "president apartment" ? price *= 0.85 : price;
  24.  
  25.             _ = rating == "positive" ? price *= 1.25 : price *= 0.9;
  26.            
  27.             Console.WriteLine($"{price:f2}");
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement