C# Need inputs in different lines

后端 未结 3 1730
伪装坚强ぢ
伪装坚强ぢ 2020-12-22 11:51

I am trying to create a program that is will take letters as input only and not duplicated. I am getting error when i put one letter in an input. This is what i need to do,

3条回答
  •  忘掉有多难
    2020-12-22 12:36

    this is you problem

    for (int i = 0; i < 5; i++)

    this is your fix:

     static void Main(string[] args)
                {
                    char[] Array = new char[5];
                    Console.WriteLine("Please Enter 5 Letters B/W a through j only: ");
                    string letters = "abcdefghij";
    
                    char[] read = Console.ReadLine().ToLower().ToCharArray();
    
                    //loop through array
                    for (int i = 0; i < read.Length; i++)
                    {
                        if (letters.Contains(read[i]) && !Array.Contains(read[i]))
                        {
                            Array[i] = read[i];
                        }
                        else
                        {
                            Console.WriteLine("You have entered an incorrect value");
                        }
    
                    }
    
                    Console.WriteLine("You have Entered the following Inputs: ");
                    for (int i = 0; i < Array.Length; i++)
                    {
                        Console.WriteLine(Array[i]);
                    }
                    Console.ReadKey();
                }
    

提交回复
热议问题