Advertisement
clipro

Untitled

Nov 10th, 2018
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.08 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace exr_10_partyInvitation
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             // declare variables
  15.             string name = "";
  16.             int allNames = 0;
  17.             int invited = 0;
  18.             int invalidNames = 0;
  19.  
  20.             while (true)
  21.             {
  22.                 name = Console.ReadLine();
  23.  
  24.                 if (name == "Statistic") break;
  25.                 int letters = 0;
  26.  
  27.                 if (name != "")
  28.                 {
  29.                     // loop each letter
  30.                     for (int i = 0; i < name.Length; i++)
  31.                     {
  32.                         int n = (int)name[i];
  33.  
  34.                         // check if it is a latin letter
  35.                         if ((n >= 65 && n <= 90) || (n >= 97 && n <= 122))
  36.                         {
  37.                             letters++;
  38.                         }
  39.                     }
  40.                     // if all letters are here so it is valid name
  41.                     if (letters == name.Length)
  42.                     {
  43.                         TextInfo myTI = new CultureInfo("en-US", false).TextInfo;
  44.                         Console.WriteLine(myTI.ToTitleCase(name));
  45.                         invited++;
  46.                     }
  47.                     else
  48.                     {
  49.                         Console.WriteLine("Invalid name!");
  50.                         invalidNames++;
  51.                     }
  52.                 }
  53.                 else
  54.                 {
  55.                     Console.WriteLine("Invalid name!");
  56.             invalidNames++;
  57.                 }
  58.                 // count all names
  59.                 allNames++;
  60.             }
  61.  
  62.             // print the statistic
  63.             Console.WriteLine($"Valid names are {100.00 * invited / allNames:F2}% from {allNames} names.");
  64.             Console.WriteLine($"Invalid names are {100.00 * (allNames - invited) / allNames:F2}% from {allNames} names.");
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement