public static void EndMenu(Vacation[] Venue, int Venues) { String inputWhatNow; int d; string[] addOptions = { "A", "a", "Add", "add" }; Console.Write("Type A to add more venues, or enter the venue number to display it's information\n"); inputWhatNow = Console.ReadLine(); if (int.TryParse(inputWhatNow, out d)) //if the user puts in a number, they will get back information on that venue, assuming the number is with the range of existing venues. { if (d > 0 && d <= Venues) { d = d - 1; Console.WriteLine(""); Console.WriteLine(Venue[d].ToString()); Console.WriteLine(""); EndMenu(Venue, Venues); } else { Console.Write("Venue out of range!\n"); } } foreach (string test in addOptions) //tests input against a number of options so the user can type out "Add", or simply "a" { if (inputWhatNow.Equals(test)) { int newVenues = AskForVenues(); Array.Resize(ref Venue, Venue.Length + newVenues); for (int i = 0; i < newVenues; i++) //a loop that adds new venues without overwriting old ones { Venue[i + Venues] = new Vacation(); Console.WriteLine("Venue #{0}", i + 1 + Venues); DescribeVenues(out Venue[i + Venues]); } //Cleans up, adds new venues to the running total and reruns this method. Venues = Venues + newVenues; EndMenu(Venue, Venues); } } //Assuming none of the if conditions were met, input is considered invalid and this method restarts. Console.Write("Invalid input.\n"); EndMenu(Venue, Venues); }
static void Main(string[] args) { //Tells the user how to use the program Console.WriteLine("This program will help you plan your vacation!"); Console.WriteLine("First, you will input the number of places you would like to go,"); Console.WriteLine("then input information about each."); int Venues = AskForVenues(); //Makes an array for the number of venues, accessed with Venue[i] where i=venue number Vacation[] Venue = new Vacation[Venues]; //The user inputs descriptions for venues 0 through i for (int i = 0; i < Venues; i++) { Venue[i] = new Vacation(); Console.WriteLine("Venue #{0}", i + 1); DescribeVenues(out Venue[i]); } //Takes the array and current number of venues to the end menu EndMenu(Venue, Venues); }