Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace PersonalTitles
- {
- class Program
- {
- static void Main(string[] args)
- {
- double age = double.Parse(Console.ReadLine());
- string gender = Console.ReadLine();
- if (age < 16 && gender == "m")
- {
- Console.WriteLine("Master");
- }
- else if (age >=16 && gender == "m")
- {
- Console.WriteLine("Mr.");
- }
- else if (gender == "f" && age < 16)
- {
- Console.WriteLine("Miss");
- }
- else if (gender == "f" && age >= 16)
- {
- Console.WriteLine("Ms.");
- }
- }
- }
- }
- Или така:
- using System;
- namespace PersonalTitles
- {
- class Program
- {
- static void Main(string[] args)
- {
- double age = double.Parse(Console.ReadLine());
- string gender = Console.ReadLine();
- if (age < 16)
- {
- if (gender == "m")
- {
- Console.WriteLine("Master");
- }
- else if (gender == "f")
- {
- Console.WriteLine("Miss");
- }
- }
- else
- {
- if (gender == "m")
- {
- Console.WriteLine("Mr.");
- }
- else if (gender == "f")
- {
- Console.WriteLine("Ms.");
- }
- }
- }
- }
- }
- Тарикатско с тернарен оператор:
- using System;
- namespace PersonalTitles
- {
- class Program
- {
- static void Main(string[] args)
- {
- double age = double.Parse(Console.ReadLine());
- string gender = Console.ReadLine();
- Console.WriteLine(age < 16 ? (gender == "m" ? "Master" : "Miss") : (gender == "m" ? "Mr." : "Ms."));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement