-4
   string[,] Arr = new string[4, 5]{{"1A" , " 2A" , " 3A" , " 4A" , " 5A"},
            {"1B" , " 2B" , " 3B" , " 4B" , " 5B"},
            {"1C" , " 2C" , " 3C" , " 4C" , " 5C"},
            {"1D" , " 2D" , " 3D" , " 4D" , " 5D"}};

                Console.WriteLine("List of availabe seats.");
                Console.WriteLine();

                for (int s = 0; s < Arr.Length; s++)
                {

                    for (int i = 0; i < Arr.GetLength(0); i++)
                    {
                        for (int k = 0; k < Arr.GetLength(1); k++)
                        {
                            Console.Write(Arr[i, k]);
                        }
                        Console.WriteLine();
                    }

                    Console.WriteLine("Enter your seat: ");
                    string textToReplace = Console.ReadLine() ;
                    for (int row = Arr.GetLowerBound(0); row <= Arr.GetUpperBound(0); ++row)
                    {
                        for (int column = Arr.GetLowerBound(1); column <= Arr.GetUpperBound(1); ++column)
                            if (Arr[row, column].Contains( textToReplace))
                            {
                                Arr[row, column] = " X ";


                            }

How to ignore cases and to output "Already Taken" and "Fully Booked" if the seat is taken or full? If I use StringComparison.CurrentCultureIgnoreCase its error because .Contains is only for int. Am I right? And I don't get the logic to output "Already Taken" and "Fully Booked" if the seat is taken or full.

Ezekiel
  • 9
  • 3
  • 2
    The question quality filter exists for a reason. Don't try to circumvent it with nonsense text. *Describe the problem*. In what way does this code not work as expected? Is there an error? Unexpected behavior? Be specific. – David Oct 06 '14 at 02:56
  • I think your question is why even if [`Contains` calls `IndexOf`](http://stackoverflow.com/questions/498686/is-string-contains-faster-than-string-indexof) it does not let me specify comparison options unlike [String.IndexOf](http://msdn.microsoft.com/en-us/library/system.string.indexof%28v=vs.110%29.aspx)... The answer will be "just because"... – Alexei Levenkov Oct 06 '14 at 03:15

2 Answers2

0

Written for one iteration. you can change it if required.

string[, ] Arr = new string[4, 5]
    {
    {
    "1A", " 2A", " 3A", " 4A", " 5A"
    }

    , {
    "1B", " 2B", " 3B", " 4B", " 5B"
    }

    , {
    "1C", " 2C", " 3C", " 4C", " 5C"
    }

    , {
    "1D", " 2D", " 3D", " 4D", " 5D"
    }
    };
    Console.WriteLine("List of seats.");
    Console.WriteLine();
    var fullyBooked = false;
    for (int i = 0; i < Arr.GetLength(0); i++)
    {
        for (int k = 0; k < Arr.GetLength(1); k++)
        {
            Console.Write(Arr[i, k]);
            fullyBooked = Arr[i, k] == "X" ? true : false;
        }

        Console.WriteLine();
    }

    if (!fullyBooked)
    {
        Console.WriteLine("Enter your seat: ");
        string textToReplace = Console.ReadLine();
        for (int i = 0; i < Arr.GetLength(0); i++)
        {
            for (int k = 0; k < Arr.GetLength(1); k++)
            {
                if (Arr[i, k] == textToReplace)
                {
                    Arr[i, k] = " X ";
                }
            }
        }

        for (int i = 0; i < Arr.GetLength(0); i++)
        {
            for (int k = 0; k < Arr.GetLength(1); k++)
            {
                Console.Write(Arr[i, k]);
            }

            Console.WriteLine();
        }
    }
    else
    {
        Console.WriteLine("Fully Booked ");
    }
vikas
  • 931
  • 6
  • 11
0

Let me preface this with I've never used C# before.

But I think what you're looking for are boolean values to determine whether or not your seat is taken or your flight is fully booked?

Try:

Console.WriteLine("Enter your seat: ");
string textToReplace = Console.ReadLine() ;
boolean isFullyBooked = true;
boolean isSeatTaken = true;
for (int row = Arr.GetLowerBound(0); row <= Arr.GetUpperBound(0); ++row)
{
    for (int column = Arr.GetLowerBound(1); column <= Arr.GetUpperBound(1); ++column)
        if (Arr[row, column].Contains( textToReplace))
        {
            Arr[row, column] = " X ";
            isSeatTaken = false;
        }
        if(!Arr[row, column].Contains(" X "))
        {
            isFullyBooked = false;
        }
    }
}
if(isFullyBooked)
{
    Console.WriteLine("Fully Booked");
}
if(isSeatTaken)
{
    Console.WriteLine("Already Taken");
}

If it cannot find your seat then it will output Already Taken, if all the elements are an " X " then it will output Fully Booked.

TomDillinger
  • 194
  • 7
  • Thanks, but it outputs 4 Line of "Already Taken" How can I output only one? :( And if the column 1 is all "X" it outputs Fully Booked. – Ezekiel Oct 06 '14 at 03:48
  • If you move the boolean setter and relevant if statement to the appropriate for loop it should only print once. It is printing 4 times because it is currently inside this loop: for (int s = 0; s < Arr.Length; s++) – TomDillinger Oct 06 '14 at 05:13