2 Replies - 2906 Views - Last Post: 01 October 2009 - 12:09 PM Rate Topic: -----

#1 pschenk1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 01-October 09

READ ARRAY FROM COMMAND LINE INPUT

Post icon  Posted 01 October 2009 - 11:32 AM

Need an example of how to display numbers from command line.

public class Unique
{
	static void Main()
		{
			displayNumbers();
		}
	
	// read 5 numbers entered by user
	public static void displayNumbers()
	{

		int[] enteredNumbers = new int[5];
		int count = 0;
		int entered = 0;
		int number;

		while (entered < enteredNumbers.Length)
		{
			Console.WriteLine("Please enter a number between 10 and 100:");

			number = Convert.ToInt32(Console.ReadLine()); 
				
			  if (number >= 10 && number <= 100)
			{
				Console.WriteLine("{0}", enteredNumbers[number]);
	entered++;
		   }



Is This A Good Question/Topic? 0
  • +

Replies To: READ ARRAY FROM COMMAND LINE INPUT

#2 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: READ ARRAY FROM COMMAND LINE INPUT

Posted 01 October 2009 - 11:45 AM

try this..

static void Main(string[] args)
{
    displayNumbers();
}

private static void displayNumbers()
{
    // this will limit you to only
    //    allowing 5 numbers to be entered
    int[] enteredNumbers = new int[5];
    int count = 0;
    int entered = 0;
    int number;

    while (entered < enteredNumbers.Length)
    {
        Console.WriteLine("Please enter a number between 10 and 100:");
        number = Convert.ToInt32(Console.ReadLine());

        if (number >= 10 && number <= 100)
        {
            enteredNumbers[entered] = number;
            entered++;
        }
    }

    Console.WriteLine();
    Console.WriteLine("The numbers entered were: ");

    for (int i = 0; i < enteredNumbers.Length; i++)
    {
        Console.WriteLine(enteredNumbers[i]);
    }

    Console.Read();
}


Was This Post Helpful? 0
  • +
  • -

#3 pschenk1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 01-October 09

Re: READ ARRAY FROM COMMAND LINE INPUT

Posted 01 October 2009 - 12:09 PM

Thanks very much, this helps. I understand it better now.



View Posteclipsed4utoo, on 1 Oct, 2009 - 10:45 AM, said:

try this..

static void Main(string[] args)
{
    displayNumbers();
}

private static void displayNumbers()
{
    // this will limit you to only
    //    allowing 5 numbers to be entered
    int[] enteredNumbers = new int[5];
    int count = 0;
    int entered = 0;
    int number;

    while (entered < enteredNumbers.Length)
    {
        Console.WriteLine("Please enter a number between 10 and 100:");
        number = Convert.ToInt32(Console.ReadLine());

        if (number >= 10 && number <= 100)
        {
            enteredNumbers[entered] = number;
            entered++;
        }
    }

    Console.WriteLine();
    Console.WriteLine("The numbers entered were: ");

    for (int i = 0; i < enteredNumbers.Length; i++)
    {
        Console.WriteLine(enteredNumbers[i]);
    }

    Console.Read();
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1