0

I start dicoverig C# today ... as you know there is some difuculties

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
       int[] arr = new int[3];
            int i;
            for (i=0; i < 3; i++)
            {
                arr[i] = Console.Read();
            }
            for (int k = 0; k < 3; k++)
            {
                Console.Write(arr[k]);
            }     

            Console.ReadKey();
        }

    }
}

this code didn't work with me when i compiled it ...it make me put value for one time then he print other values ! any one here to help

3 Answers 3

3

try this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
  class Program
  {
    static void Main(string[] args)
    {
      int[] arr = new int[3];
      int i;
      for (i = 0; i < 3; i++)
      {
        arr[i] = Convert.ToInt32(Console.ReadLine());
      }
      for (int k = 0; k < 3; k++)
      {
        Console.WriteLine(arr[k]);
      }

      Console.ReadKey();
    }

  }

}

Bye.

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

Comments

1

If i understand you correcrtly this is what you want

int[] arr = new int[3];
            for (int i = 0; i < 3; i++)
                arr[i] = Convert.ToInt32(Console.ReadLine());
            for (int k = 0; k < 3; k++)
                Console.WriteLine(arr[k]);

            Console.ReadKey();

Comments

1

Instead of

arr[i] = Console.Read();

try this:

arr[i] = (int)Console.ReadKey().KeyChar;

Console.Read() will continue to read the same character over and over as it will still be considered the next character from the input stream. The Console.ReadKey() function reads keys as they are pressed.

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.