DyNaMiXx7

Untitled

Nov 1st, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     static void Main(string[] args)
  6.     {
  7.         double totalCounterName = 0;
  8.         double validNames = 0;
  9.         double invalidNames = 0;
  10.  
  11.         bool isValidName = true;
  12.         while (true)
  13.         {
  14.             string name = Console.ReadLine();
  15.             if (name == "Statistic")
  16.             {
  17.                 break;
  18.             }
  19.  
  20.             isValidName = true;
  21.             totalCounterName++;
  22.  
  23.             for (int i = 0; i < name.Length; i++)
  24.             {
  25.                 if (!Char.IsLetter(name[i]))
  26.                 {
  27.                     Console.WriteLine("Invalid name!");
  28.                     isValidName = false;
  29.                     invalidNames++;
  30.                     break;
  31.                 }
  32.             }
  33.  
  34.             if (isValidName)
  35.             {
  36.                 validNames++;
  37.                 name = name[0].ToString().ToUpper() + name.Substring(1, name.Length - 1).ToLower();
  38.                 Console.WriteLine(name);
  39.             }
  40.         }
  41.  
  42.         double peopleComingPercent = (validNames / totalCounterName) * 100;
  43.         double peopleNotComingPercent = (invalidNames / totalCounterName) * 100;
  44.  
  45.         Console.WriteLine($"Valid names are {peopleComingPercent:F2}% from {totalCounterName} names.");
  46.         Console.WriteLine($"Invalid names are {peopleNotComingPercent:F2}% from {totalCounterName} names.");
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment