Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Globalization;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace exr_10_partyInvitation
- {
- class Program
- {
- static void Main(string[] args)
- {
- // declare variables
- string name = "";
- int allNames = 0;
- int invited = 0;
- int invalidNames = 0;
- while (true)
- {
- name = Console.ReadLine();
- if (name == "Statistic") break;
- int letters = 0;
- if (name != "")
- {
- // loop each letter
- for (int i = 0; i < name.Length; i++)
- {
- int n = (int)name[i];
- // check if it is a latin letter
- if ((n >= 65 && n <= 90) || (n >= 97 && n <= 122))
- {
- letters++;
- }
- }
- // if all letters are here so it is valid name
- if (letters == name.Length)
- {
- TextInfo myTI = new CultureInfo("en-US", false).TextInfo;
- Console.WriteLine(myTI.ToTitleCase(name));
- invited++;
- }
- else
- {
- Console.WriteLine("Invalid name!");
- invalidNames++;
- }
- }
- else
- {
- Console.WriteLine("Invalid name!");
- invalidNames++;
- }
- // count all names
- allNames++;
- }
- // print the statistic
- Console.WriteLine($"Valid names are {100.00 * invited / allNames:F2}% from {allNames} names.");
- Console.WriteLine($"Invalid names are {100.00 * (allNames - invited) / allNames:F2}% from {allNames} names.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement