using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace Vektorer_och_sökning { internal class Program { static void Main(string[] args) { // Array backpack, storing up to 5 objects. Written by Anthony Persson. NTI Skolan. string[] objectsVector = new string[5]; bool loop = true; while(loop) { // Loop menu Thread.Sleep(750); Console.WriteLine("Welcome to the menu!"); Thread.Sleep(250); Console.WriteLine("--------------------"); Thread.Sleep(250); Console.WriteLine("[1] Add an object"); Thread.Sleep(250); Console.WriteLine("[2] Inspect the backpack"); Thread.Sleep(250); Console.WriteLine("[3] Search backpack"); Thread.Sleep(250); Console.WriteLine("[4] Suprice"); Thread.Sleep(250); Console.WriteLine("[5] Exit"); if (Int32.TryParse(Console.ReadLine(), out int userInput)) { if(userInput == 1) { // Add an object into the backpack using Array for (int i = 0; i < objectsVector.Length; i++) { Console.Write("Enter five items: "); objectsVector[i] = Console.ReadLine(); } } else if(userInput == 2) { // Print out the names inside array stored by userInput using foreach Console.Clear(); Console.WriteLine("Current objects inside the backpack are:"); Thread.Sleep(500); foreach (var items in objectsVector) // Issue: checking if vector is empty, then display slot is empty. if(objectsVector == null) { Console.WriteLine("Slot is currently empty."); } else { // Issue, printing out message 5 times Console.WriteLine("Current items inside the backpack are:"); Console.WriteLine(items); } } else if(userInput == 3) { // Search for stored word Console.Clear(); Thread.Sleep(250); Console.WriteLine("This is a search function, please. Tell me what you're looking for:"); string searchWord = Console.ReadLine(); bool foundButton = false; for(int i = 0; i < objectsVector.Length; i++) { if(searchWord.ToUpper() == objectsVector[i].ToUpper()) { foundButton = true; Console.WriteLine("The name exists inside the vector on spot " + i + "!"); } } if(foundButton == false) { Console.WriteLine("Word was not found."); } } else if(userInput == 4) { // Technoblade never dies System.Diagnostics.Process.Start("https://www.youtube.com/watch?v=R_fZjGm2OrM"); loop = false; } else if(userInput == 5) { // Exit application Console.Clear(); Console.WriteLine("Thank you for this time!"); Thread.Sleep(2500); loop = false; } } else { // Wrong input Console.Clear(); Thread.Sleep(250); Console.WriteLine("Sorry, I did not understand your request."); Thread.Sleep(250); Console.WriteLine("------------------------------------------"); Thread.Sleep(500); } } } } }