❔ Backpack Array / C#
'using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace vektorerochsökning
{
internal class Program
{
static void Main(string[] args)
{
//Keep program running as long as the user doesn't choose to quit the program.
bool continueLoop = true;
//Create string vector with 5 elements
string[] myObject = new string[5];
myObject[0] = "";
myObject[1] = "";
myObject[2] = "";
myObject[3] = "";
myObject[4] = "";
while (continueLoop) { Console.WriteLine("This is a backpack, and this is what you can do with it"); Console.WriteLine("[1] Add a object"); Console.WriteLine("[2] Skriv ut alla föremål"); Console.WriteLine("[3] Sök i ryggsäcken"); Console.WriteLine("[4] Avsluta ryggsäcken"); //The user makes a choice Console.Write("Choose: "); int menuAlt = Convert.ToInt32(Console.ReadLine());
{ switch (menuAlt) { case 1: // Add a object (eg. fruit or something) - FOR every element in my vector // Add a string value to the element Console.WriteLine("What do you want to add to the backpack? "); myObject = Console.ReadLine(); Console.WriteLine();
break; }'
while (continueLoop) { Console.WriteLine("This is a backpack, and this is what you can do with it"); Console.WriteLine("[1] Add a object"); Console.WriteLine("[2] Skriv ut alla föremål"); Console.WriteLine("[3] Sök i ryggsäcken"); Console.WriteLine("[4] Avsluta ryggsäcken"); //The user makes a choice Console.Write("Choose: "); int menuAlt = Convert.ToInt32(Console.ReadLine());
{ switch (menuAlt) { case 1: // Add a object (eg. fruit or something) - FOR every element in my vector // Add a string value to the element Console.WriteLine("What do you want to add to the backpack? "); myObject = Console.ReadLine(); Console.WriteLine();
break; }'
3 Replies
How to add multiple objects to the backpack with arrays?
Arrays have fixed size
So you'll need to insert items at a specific index
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.