views:

70

answers:

3

I've learned how to store a single input of data and return a value based on it.

What I want to do is obtain multiple inputs from the user, then return a result. But how do I define each input?

Like, if I want the first input to be known as 'stock', and the second as 'value', how do I do that?

I hope I explained my question properly.

+2  A: 
string stock = Console.ReadLine();
string value = Console.ReadLine();

.. Or am I interpreting your question incorrectly?

Edit: As a response to your comment:

string input = Console.ReadLine(); //enter stock value
string[] parts = input.split(new String[]{ " " });

stock = parts[1];
value = parts[2];  

If you wish to actually define a "new" variable named "stock" and give it the value "value", you should look into System.Collections.Generic.Dictionary<key, value>

ItzWarty
So when it's run, each input will be stored in that order? Basically, I want to make sure that if I have it say "Enter stock value" it will store the data input there as stock and so on.
Slateboard
A: 

If @ItzWarty's answer isn't quite what you want, this would allow your users to enter multiple values in one line:

string line = Console.ReadLine();

//whatever chars you wish to split on...
string[] inputs = line.Split(new char[] {' ', ',', ';'}); 

string stock = inputs[0];
string value = inputs[1];
Austin Salonen
A: 

You can try this code:

        string name = String.Empty;
        string department = String.Empty;
        int age = 0;


        Console.WriteLine("Please, enter the name of your employee, then press ENTER");
        name = Console.ReadLine();
        Console.WriteLine("Please, enter the department of your employee, then press ENTER");
        department = Console.ReadLine();
        Console.WriteLine("Please, enter the age of your employee, then press ENTER");
        Int32.TryParse(Console.ReadLine(), out age); // default 0


        Console.WriteLine("Name: " + name);
        Console.WriteLine("Department: " + department);
        Console.WriteLine("Age: " + age.ToString());
Javier Morillo
Thank you very much. This is all starting to make sense to me. I do apologize if my question was too vague or lacked enough information, but you have provided several good answers here. I really appreciate it.
Slateboard
You are welcome :-)
Javier Morillo