Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- public static List<string> guestNames = new List<string>();
- public static int guestCounter = 0;
- public static bool isRunning = true;
- static void Main(string[] args)
- {
- while (isRunning)
- {
- GetGuestName();
- GetGuestCount();
- if (GetGuestName() == false || GetGuestCount() == false)
- {
- isRunning = false;
- }
- }
- GetPartyInfo();
- }
- private static bool GetGuestName()
- {
- Console.Write("Please enter your name or type exit: ");
- string userInput = Console.ReadLine();
- bool isInvalidInput = int.TryParse(userInput, out int numCheck);
- if (isInvalidInput == false)
- {
- if (userInput.ToLower() != "exit")
- {
- guestNames.Add(userInput);
- guestCounter += 1;
- }
- else if (userInput.ToLower() == "exit")
- {
- return false;
- }
- }
- else if (isInvalidInput == true) ;
- {
- Console.WriteLine("Please enter a valid name: ");
- GetGuestName();
- }
- return true;
- }
- private static bool GetGuestCount()
- {
- Console.Write("Please enter the number of guests in your party or exit: ");
- string userInput = Console.ReadLine();
- bool isValidInput = int.TryParse(userInput, out int partyCount);
- if (isValidInput == true)
- {
- guestCounter += partyCount;
- }
- else if (isValidInput == false)
- {
- if (userInput.ToLower() == "exit")
- {
- return false;
- }
- else
- {
- Console.WriteLine("Please enter a valid number...");
- }
- }
- return true;
- }
- private static void GetPartyInfo()
- {
- for (int i = 0; i < guestNames.Count; i++)
- {
- Console.WriteLine(guestNames[i]);
- }
- Console.WriteLine($"There are { guestCounter } guests at the party.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement