Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. class Program
  2. {
  3. public static List<string> guestNames = new List<string>();
  4. public static int guestCounter = 0;
  5. public static bool isRunning = true;
  6.  
  7. static void Main(string[] args)
  8. {
  9. while (isRunning)
  10. {
  11. GetGuestName();
  12. GetGuestCount();
  13.  
  14. if (GetGuestName() == false || GetGuestCount() == false)
  15. {
  16. isRunning = false;
  17. }
  18. }
  19.  
  20. GetPartyInfo();
  21. }
  22.  
  23. private static bool GetGuestName()
  24. {
  25. Console.Write("Please enter your name or type exit: ");
  26. string userInput = Console.ReadLine();
  27.  
  28. bool isInvalidInput = int.TryParse(userInput, out int numCheck);
  29.  
  30. if (isInvalidInput == false)
  31. {
  32. if (userInput.ToLower() != "exit")
  33. {
  34. guestNames.Add(userInput);
  35. guestCounter += 1;
  36. }
  37.  
  38. else if (userInput.ToLower() == "exit")
  39. {
  40. return false;
  41. }
  42. }
  43.  
  44. else if (isInvalidInput == true) ;
  45. {
  46. Console.WriteLine("Please enter a valid name: ");
  47. GetGuestName();
  48. }
  49.  
  50. return true;
  51. }
  52.  
  53. private static bool GetGuestCount()
  54. {
  55. Console.Write("Please enter the number of guests in your party or exit: ");
  56. string userInput = Console.ReadLine();
  57.  
  58. bool isValidInput = int.TryParse(userInput, out int partyCount);
  59.  
  60. if (isValidInput == true)
  61. {
  62. guestCounter += partyCount;
  63. }
  64.  
  65. else if (isValidInput == false)
  66. {
  67. if (userInput.ToLower() == "exit")
  68. {
  69. return false;
  70. }
  71. else
  72. {
  73. Console.WriteLine("Please enter a valid number...");
  74. }
  75. }
  76.  
  77. return true;
  78. }
  79. private static void GetPartyInfo()
  80. {
  81. for (int i = 0; i < guestNames.Count; i++)
  82. {
  83. Console.WriteLine(guestNames[i]);
  84. }
  85.  
  86. Console.WriteLine($"There are { guestCounter } guests at the party.");
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement