2

So I'm a total beginner in programming and I don't have any idea how this works. But this is probably the easiest thing being asked. So I want to create a program where you sell things and stuff. The customer is being lead to a menu in which where he/she will select a thing to buy. Every product has its specified letter for the user to enter. So what I want to know is, how do you assign values to identifiers using array and call them when the customer chooses a corresponding letter?

Like for example, [A]Product 1 [B]Product 2

The customer inputs A so product 1 will be called and along with it is the product's price. Then using the 'do-while' loop, the program will then ask if the customer wants to have another transaction and if the customer chooses YES, the program will then repeat, and the customer chooses, and the price of the new item will be added to older one. Like: Product 1 + Product 2 = Total Price

Then if the customer chooses NO, it will print a receipt with the items bought, the amount and the total. Please help me. If it's not for the array, maybe I can do this, but yeah. :(

Thanks. Btw, if you want to see my code, here it is. This is just the design though just to give you an idea. Thanks again! I hope you can help me. Please.

string ans;

do
{
  switch(group)
  { 
    case "S":
    case "s":
      Console.WriteLine("***************************************************************");
      Console.WriteLine("*                         SHINee                              *");
      Console.WriteLine("***************************************************************");
      Console.WriteLine("*  Items:                         *  Bundles for Concert      *");
      Console.WriteLine("*   | Lanyards/Lace      P200     *    [O]BUNDLE 1 P450       *");
      Console.WriteLine("*     [A]Onew                     *     T-SHIRT(Free Size)    *");
      Console.WriteLine("*     [B]Jonghyun                 *     Lightstick            *");
      Console.WriteLine("*     [C]Minho                    *     Banner                *");
      Console.WriteLine("*     [D]Key                      *                           *");
      Console.WriteLine("*     [E]Taemin                   *    [P]BUNDLE 2 P590       *");
      Console.WriteLine("*                                 *      T-SHIRT(Free Size)   *");
      Console.WriteLine("*   | Bag Tag            P60      *      2 Lighsticks         *");
      Console.WriteLine("*     [G]Onew                     *      Banner               *");
      Console.WriteLine("*     [H]Jonghyun                 *                           *");
      Console.WriteLine("*     [I]Minho                    *    [Q]BUNDLE 3 P720       *");
      Console.WriteLine("*     [J]Key                      *      T-SHIRT(Free Size)   *");
      Console.WriteLine("*     [K]Taemin                   *      2 Lighsticks         *");
      Console.WriteLine("*                                 *      Banner               *");
      Console.WriteLine("*   | Couple Keychain    P90      *      Balloon              *");
      Console.WriteLine("*     [M]2Min                     *                           *");
      Console.WriteLine("*     [N]JongKey                  *                           *");
      Console.WriteLine("*                                 *                           *");
      Console.WriteLine("*                                 *                           *");
      Console.WriteLine("***************************************************************");
      Console.WriteLine("");
      Console.WriteLine("==========================");
      Console.Write("Input letter of choice: ");

      string merchshin = Console.ReadLine();
      break;
  }

  Console.Write("Do you want to do another transaction?");
  ans = Console.ReadLine();
  Console.WriteLine("==========================");
  Console.Clear();
}
while (ans == "y" || ans == "Y");
Console.ReadLine();

3 Answers 3

2

You are looking for a key-value pair implementation like dictionary.

If that doesn't do the trick, you could always take a look at tools like Redis (http://redis.io), which is basically an advanced key-value store.

Sign up to request clarification or add additional context in comments.

1 Comment

"If you want to sort an array, you could use Array.Sort ... if that doesn't work, try Google MapReduce!" :p
1

I would say using a dictionary with a class containing your product information.

// Create the dictionary.
Dictionary<string, Product> productInfo = new Dictionary<string, Product>();

//Create products and there information.
productInfo.Add("ProductOne", new Product { Name = "name", Price=1.99, Description="description" };
productInfo.Add("ProductTwo", new Product { Name = "name", Price=1.99, Description="description" };
productInfo.Add("ProductThree", new Product { Name = "name", Price=1.99, Description="description" };

To create the class you would just need

public class Product
{
    //product properties.
    public string Name { get; set; }
    public double Price { get; set; }
    public string Description { get; set; }

    public Product()
    { }
}

To access the dictionary just use something like...

Console.WriteLine(string.format("Product Name: {0} Price:{1}", productInfo["ProductOne"].Name, productInfo["ProductOne"].Price));

Comments

0

What you are describing is a "key-value pair", for this you usually use a Dictionary.

For example:

// Create a dictionary of pairs of 'strings' (the item) and 'ints' (the prices)
Dictionary<string, int> pricesByItem = new Dictionary<string, int>();

// Add items and their prices.
pricesByItem.add("Sandwhich", 3);
pricesByItem.add("Hamburger", 4);
pricesByItem.add("Cheese", 5);

// Get the price of an item
int priceOfASandwhich = pricesByItem["Sandwhich"];
Console.WriteLine(priceOfASandwhich);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.