Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Weather2
- {
- class Program
- {
- static void Main()
- {
- double degrees = double .Parse(Console.ReadLine());
- if (degrees >= 5 && degrees < 12)
- {
- Console.WriteLine("Cold");
- }
- else if (degrees >= 12 && degrees < 15)
- {
- Console.WriteLine("Cool");
- }
- else if (degrees >=15 && degrees <= 20)
- {
- Console.WriteLine("Mild");
- }
- else if (degrees > 20 && degrees < 26)
- {
- Console.WriteLine("Warm");
- }
- else if (degrees >= 26 && degrees <= 35)
- {
- Console.WriteLine("Hot");
- }
- else
- {
- Console.WriteLine("unknown");
- }
- }
- }
- }
- Решение с тернарен оператор:
- using System;
- namespace Weather2
- {
- class Program
- {
- static void Main()
- {
- double degrees = double.Parse(Console.ReadLine());
- string weather = degrees >= 5 && degrees < 12 ? "Cold" :
- degrees >= 12 && degrees < 15 ? "Cool" :
- degrees >= 15 && degrees <= 20 ? "Mild" :
- degrees > 20 && degrees < 26 ? "Warm" :
- degrees >= 26 && degrees <= 35 ? "Hot" : "unknown";
- Console.WriteLine(weather);
- }
- }
- }
Add Comment
Please, Sign In to add comment