Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Ages
- {
- class Program
- {
- static void Main(string[] args)
- {
- int age = int.Parse(Console.ReadLine());
- string personStatus = "";
- if (age >= 0 && age <= 2)
- {
- personStatus = "baby";
- }
- else if (age >= 3 && age <= 13)
- {
- personStatus = "child";
- }
- else if (age >= 14 && age <= 19)
- {
- personStatus = "teenager";
- }
- else if (age >= 20 && age <= 65)
- {
- personStatus = "adult";
- }
- else if (age > 65)
- {
- personStatus = "elder";
- }
- Console.WriteLine(personStatus);
- }
- }
- }
- Рещение с тернатен оператор:
- using System;
- namespace Ages
- {
- class Program
- {
- static void Main(string[] args)
- {
- int age = int.Parse(Console.ReadLine());
- string personStatus =
- age >= 0 && age <= 2 ? "baby" :
- age >= 3 && age <= 13 ? "child" :
- age >= 14 && age <= 19 ? "teenager" :
- age >= 20 && age <= 65 ? "adult" :
- age > 65 ? "elder" : "";
- Console.WriteLine(personStatus);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement