Advertisement
kyrathasoft

getFour

Jul 21st, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using System;
  2. using TestInput;
  3. /*
  4. from Lesson 5 of C# console programming tutorial series at following URL:
  5. http://williammillerservices.com/windows-c-console-programming/
  6. demonstrates while loop and safe parsing of string to integer. To
  7. compile, requires tester1.cs
  8. GitHub gist -> https://gist.github.com/kyrathasoft/619b3addf6d7204d325a04ff77859a77
  9. Pastebin.com -> https://pastebin.com/3N76Jz03
  10. Dependencies: tester1.cs
  11. -> https://gist.github.com/kyrathasoft/35357f7fee1c427693323286111e5e43
  12. */
  13. namespace GetInteger4FromKeyboard
  14. {
  15.     class CanIHavvaFourPlease
  16.     {
  17.         static void Main(string[] args)
  18.         {
  19.             //var to hold keyboard input
  20.             string sData = String.Empty;
  21.  
  22.             //var to hold sData parsed to an Int
  23.             int i = 0;
  24.  
  25.             /* our loop will be entered at LEAST
  26.             once; initializing i to zero sees to
  27.             that... */
  28.             while (i != 4)
  29.             {
  30.                 Console.Write("Please enter integer 4: ");
  31.                 sData = Console.ReadLine();
  32.                 if (Tester.IsInteger(sData))
  33.                 {
  34.                     i = Int32.Parse(sData);
  35.                 }
  36.             }
  37.  
  38.             Console.WriteLine("Thanks for entering integer {0}.",
  39.                 i.ToString());
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement